我试图配置一个WordPress网站与SSL配置.我安装了NGINX,PHP(7.4)和MySQL.
所以当我访问服务器的公共IP时,它成功加载了网站。我们也设置了DNS A记录。
假设URL是example.com
,当我访问example.com
时,它成功加载了网站,但没有HTTPS安全。我在sites-available
和sites-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;
}
}
型
1条答案
按热度按时间cedebl8k1#
字符串
添加了上面的
wp-config.php
并开始工作