[英]Redirecting all non-subdomain requests to (https)apex domain with Nginx
[英]NGINX redirecting non secure subdomain to main domain
我有托管在同一台服务器上2域假设testwebsite.com
和staging.testwebsite.com
。 我添加了nginx配置,其中存在一个问题,子域仅在非安全协议上才被重定向到主域。
http://testwebsite.com- > https://testwebsite.com =确定
https://testwebsite.com- > https://testwebsite.com =确定
http://staging.testwebsite.com- > https://testwebsite.com =不好
https://staging.testwebsite.com- > https://staging.testwebsite.com =确定
testwebsite.com
server {
root /var/www/testwebsite.com/live;
index index.html index.php index.htm index.nginx-debian.html;
server_name testwebsite.com www.testwebsite.com;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/testwebsite.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/testwebsite.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
listen 80;
listen [::]:80;
server_name testwebsite.com www.testwebsite.com;
return 301 https://testwebsite.com$request_uri;
}
staging.testwebiste.com
server {
root /var/www/testwebsite.com/staging;
index index.html index.php index.htm index.nginx-debian.html;
server_name staging.testwebsite.com www.staging.testwebsite.com;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/staging.testwebsite.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/staging.testwebsite.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
listen 80;
listen [::]:80;
server_name staging.testwebsite.com www.staging.testwebsite.com;
return 301 https://staging.testwebsite.com$request_uri;
}
谁能帮忙配置出现问题吗?
该配置在我看来还可以。
您确定不是浏览器在缓存重定向吗? 浏览器倾向于非常积极地缓存301重定向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.