我正在尝试在 nginx 服务器上配置 ssl,但它显示了错误的目录。80 端口上的 http 可以,443 端口上的 https 不行
这是我的 formazioneturismo.com.vhost
fastcgi_cache_path /var/nginx-cache/formazioneturismo.com 级别=1:2 keys_zone=$
server {
listen 443 ssl;
server_name formazioneturismo.com www.formazioneturismo.com;
ssl_certificate /etc/nginx/ssl/formazioneturismo.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
return 301 https://www.formazioneturismo.com$request_uri;
}
server {
listen *:80;
server_name formazioneturismo.com www.formazioneturismo.com;
root /var/www/formazioneturismo.com/web;
index index.php;
error_log /var/www/formazioneturismo.com/log/error.log;
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
access_log off;
log_not_found off;
}
set $skip_cache 0;
if ($request_method = POST) {
set $skip_cache 1;
}
if ($query_string != "") {
set $skip_cache 1;
}
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|index.php|sitemap$
set $skip_cache 1;
}
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wor$
set $skip_cache 1;
}
location / {
try_files $uri $uri/ /index.php?$args;
proxy_read_timeout 300;
}
location ~ \.php$ {
try_files /554f0f259d7888e056db62d833113342.htm @php;
}
location @php {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/lib/php5-fpm/web1.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache WORDPRESS_formazioneturismo.com;
fastcgi_cache_valid 1440m;
}
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jp$
access_log off; log_not_found off; expires max;
}
}
正如你可以检查到的http://www.formazioneturismo.com你通常会看到这个网站,如果你去https://www.formazioneturismo.com我看到了默认的 nginx 页面
答案1
请将文档根目录设置为监听端口 443,我还可以看到 http 位置块指向 /var/www/formazioneturismo.com/web,而 https 块可能默认为路径 /var/www/formazioneturismo.com:
server {
listen 443 ssl;
server_name formazioneturismo.com www.formazioneturismo.com;
root /var/www/formazioneturismo.com/web;
ssl_certificate /etc/nginx/ssl/formazioneturismo.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
重新启动
sudo service nginx restart
答案2
我知道这个问题已经存在一年半了,但从来没有得到过正确的回答,我知道这一点——因为我在搜索这个问题时偶然发现了这个问题。然而,正是因为这个问题,我才能够立即找到并解决问题。
fastcgi_cache_path /var/nginx-cache/formazioneturismo.com levels=1:2 keys_zone=$
这就是问题所在。这基本上(我猜我发现文档对此非常混乱)意味着“对 http 使用区域级别 1”和“对 https 使用区域级别 2”(至少这是我在脑海中翻译的)。将其切换到级别 = 2 解决了该问题。
fastcgi_cache_path /var/nginx-cache/formazioneturismo.com levels=2 keys_zone=$