我在Vesta CP上运行NGINX。 有两个单独的文件nginx.conf和snginx.conf 。 每个服务器都有一个服务器块。 我将整个站点redirect到SSL。 为此,我添加一个return 301 https://example.com$request_uri; 到nginx.conf ,然后我完全configuration了sningx.confcaching和位置块等等。
我有一个域是部分SSL /非SSL。 在这些文件中,我不是301,而是我301的位置块,像这样:
location ~ ^/(wp-login.php|wp-admin|wp-login|shop|product|my-account|checkout-2|order-pay|order-received|add-payment-method|cart) { return 301 https://domain.com$request_uri;}
而在SSL块我排除:
location ~ ^(?!/(wp-login.php|wp-admin|wp-login|shop|product|my-account|checkout-2|order-pay|order-received|add-payment-method|cart)) { return 301 http://sergerpepper.com$request_uri;}
我需要在SSL和非SSL上都有一个可用的URL,其他的都在SSL上。 这个url是网站地图。 所以这两个将工作:
http://example.com/sitemap_index.xml https://example.com/sitemap_index.xml
但是任何其他的URL只能在SSL上。 通过我以上的redirect方法,我可以在HTTP上指向一个URL,或者将它排除在HTTPS之外,但不能同时指向两者。
您的https服务器块不应将任何内容redirect到http,因为在这种情况下您不需要这样做。
您的http服务器块应该redirect所有内容,除了有问题的url:
server { listen [::]:80; listen 80; server_name .example.com; root /srv/www/example.com; location = /sitemap_index.xml { try_files $uri =404; } location / { return 301 https://$host$request_uri$is_args$args; } }