我有一种情况,尽管所有流量都应该将 http 重定向到 https,除非上下文为/publish
http{mydomain.com/*} 应该强制重定向到 https{mydomain.com},但如果 url 是 http{mydomain.com/publish},则不需要重定向。
提前致谢
最佳答案
在 nginx 中进行重定向的最佳方法是使用多个 server{}
块。
你应该没问题:
server {
server_name mydomain.com;
listen 80;
location / {
return 301 https://$server_name$request_uri;
}
location /publish {
# Here goes your usual request handling, with proxying and so on
# Nested location can be used if needed
}
}
server {
server_name mydomain.com;
listen 443;
ssl on;
# Here goes all your request handling
}
关于Nginx 条件重定向到 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40181475/