nginx如何配置location
1.nginx配置单个文件的地址映射
location /demo.txt {
alias /home/demo.txt;
}
location /demo.html {
alias /home/demo.html;
}
2.配置静态文件路由
location /static {
proxy_pass http://127.0.0.1:18091;
expires 30d;
add_header Cache-Control "public, max-age=2592000";
}
3.配置默认路由
location / {
proxy_pass http://127.0.0.1:18091;
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-Forwarded-Proto $scheme;
client_max_body_size 10M;
}
测试修改的配置是否正确
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
修改后重新加载配置
# nginx -s reload
正文到此结束
- 本文标签: nginx
- 本文链接: https://codeis.run/article/nginx-location
- 版权声明: 本文由醒醒原创发布,转载请遵循《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权