【发布时间】:2020-10-01 06:16:30
【问题描述】:
我的应用托管在基本 URL 中:https://myapp.com/
现在我想添加从“www”到“non www”/“http”到“https”的重定向,其中:
https://myapp.com/
https://www.myapp.com/
http://myapp.com/
http://www.myapp.com/
最后 3 个 URL 应该 301 重定向到第一个。
现在第二个 URL 没有被重定向,最后 2 个使用 307 重定向而不是 301 重定向。
这是我的 nginx 配置:
server {
listen 80;
server_name myapp.com www.myapp.com;
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name myapp.com www.myapp.com;
server_tokens off;
ssl_certificate /etc/nginx/conf.d/self-signed-fullchain.pem;
ssl_certificate_key /etc/nginx/conf.d/self-signed-privkey.pem;
include /etc/nginx/conf.d/options-ssl-nginx.conf;
ssl_dhparam /etc/nginx/conf.d/ssl-dhparams.pem;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location ~ ^/(api)/ {
proxy_pass http://myapp:3000;
}
}
那么我该怎么做呢?
【问题讨论】:
-
见this 答案。
标签: nginx redirect mod-rewrite http-redirect