操作.conf文件以正确重写https

我有一个nginx服务器和一个域example.com。 每个客户都有他自己的子域名,比如wsb.example.com等。他们的内容通过PHP更改,但所有子域名都被redirect到Web服务器上的相同文件夹。

我遇到的唯一问题是访问没有HTTPS的域名。 https://whatever.example.com/正常工作,但whatever.example.com会将我redirect到https://*.example.com/

我究竟做错了什么?

server { listen *:80; listen *:443 ssl; server_name *.alterament.de; index index.php; root /var/www/webapp.alterament.de/public; ssl_certificate ssl/alterament.de.crt; ssl_certificate_key ssl/alterament.de.key; if ($ssl_protocol = "") { rewrite ^/(.*) https://$server_name/$1 permanent; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location /resources { root /var/www/webapp.alterament.de; } } 

您在redirect中使用了$server_name ,这会导致使用server_name指令的内容。 这不是你想要的。

相反, 你应该用$hostreplace它 。

该configuration检查协议是否不是https并强制使用https:

 if ($ssl_protocol = "") { rewrite ^/(.*) https://$server_name/$1 permanent; } 

尝试注释掉整个块并重新启动nginx