mba*_*a12 7 nginx url-redirection
我想将所有http流量重定向到https,只有少数例外.我希望保留在http的网址中的/ exception /中的任何内容.
尝试了以下建议通过将所有http重定向到nginx中的https,除了一个文件
但它不起作用./ exception/urls将从nginx传递到apache,以便在laravel框架中进行一些php处理,但这无关紧要.
任何改进建议都非常感谢!
server {
listen 127.0.0.1:80;
location / {
proxy_pass http://127.0.0.1:7080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Accel-Internal /internal-nginx-static-location;
access_log off;
}
location /exception/ {
# empty block do nothing
# I've also tried adding "break;" here
}
return 301 https://localhost$request_uri;
}
Run Code Online (Sandbox Code Playgroud)
Nginx找到最长的匹配位置并首先处理它,但是无论如何都在处理服务器块末尾的返回.这将重定向除/ /上游之外的所有内容.
server {
listen 127.0.0.1:80;
access_log off;
location / {
return 301 https://localhost$request_uri;
}
location /exception/ {
proxy_pass http://127.0.0.1:7080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Accel-Internal /internal-nginx-static-location;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4528 次 |
| 最近记录: |