Nginx常用设置
反向代理#
http://localhost => http://api-service
location ~ ^/api {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://<API-service>:<port>;
}
添加后缀#
http://ipfs-service/<hash>.<ext> => http://ipfs-service/<hash>
location ~ ^/prefix {
rewrite ^/prefix/(.*).(<ext>)$ /$1 break;
proxy_pass http://<API-service>:<port>$1;
}
局部代理#
http://domian/AAA/static/dir/a.js => http:///static/dir/a.js
location ~ (.*)/static/(.*)$ {
proxy_ignore_client_abort on;
proxy_http_version 1.1;
proxy_pass https://<static-service>/static/$2;
}
重定向#
http://localhost/dirname (301)=> http://localhost/dirname/
location ~ ^/dirname {
return 301 " /dirname/";
}
阅读其他文章