HTTPS在Ubuntu服务器上不适用于Nginx和PHP的WordPress

zbdgwd5y  于 2024-01-05  发布在  PHP
关注(0)|答案(1)|浏览(122)

我试图配置一个WordPress网站与SSL配置.我安装了NGINX,PHP(7.4)和MySQL.
所以当我访问服务器的公共IP时,它成功加载了网站。我们也设置了DNS A记录。
假设URL是example.com,当我访问example.com时,它成功加载了网站,但没有HTTPS安全。我在sites-availablesites-enabled中创建了一个新的配置文件,并添加了以下内容。我删除了/etc/nginx.conf.d/中的配置文件

内容

server {
        listen 80;
        listen [::]:80;
        listen 443 ssl default_server;
        listen [::]:443 ssl default_server;
        ssl on;
        root /var/www/html/example.com;
        index  index.php index.html index.htm;
      
        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot

 
        server_name example.com <ip-of-the-vm>;
        
        location / {
                try_files $uri $uri/ /index.php?$args;
        }
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.4-fpm.sock;
                fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
}

字符串
我安装了certbot并使用以下命令创建了证书:

sudo certbot --nginx -d example.com -d www.example.com


当我在浏览器中访问example.com时,它会加载网站但不安全。而且我还看到它重定向(它在浏览器的URL/搜索栏中显示服务器的公共IP。它正在重定向?)
x1c 0d1x的数据
修改NGINX配置文件。

server {
listen 80;
server_name www.example.com example.com;

return 301 https://$host$request_uri;
}

server {
listen 443 ssl http2;
server_name example.com;

root /var/www/html/example.com;
index index.php;

# SSL parameters
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;

# log files
access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;

location / {
try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
}

cedebl8k

cedebl8k1#

define('WP_SITEURL', 'http://example.com');
define('WP_HOME', 'http://example.com');

字符串
添加了上面的wp-config.php并开始工作

相关问题