
nginx反向代理配置演示,包括静态资源处理,百分百成功
nginx代理配置演示,包括静态资源处理,百分百成功。 最近在测试nginx代理时,遇到了一个问题就是,可以成功接受后端处理的数据, 但是静态资源却出现了404 错误。经过搜索相关文档终于解决了nginx代理静态资源的问题。 详细代码如下。自行修改相关参数。。。
1
2
3
4
5
6
7
8
9
10
location / {
proxy_pass http://127.0.0.1:9090;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 300;
proxy_read_timeout 300;
proxy_send_timeout 300;
}
关键是下面的代码,就是nginx处理静态资源的关键。
1
2
3
4
location ^~ /static/ {
root /var/www/web/;
}
如果镜像资源和图片上传目录是分开的。就是说不在同一目录下,则要分开处理,比如
1
2
3
4
location ^~ /upload/ {
root /var/www/web/;
}
nginx -t
service nginx restart
💘 相关文章
- 解决nginx反向代理验证码不显示的方法
- Configure nginx to only allow cloudflare's IP to connect to the server shell script
- nginx: [warn] "ssl_stapling" ignored, not supported告警
- 快速简单一键搭建nginx quic的环境
- 免费的Nginx 代理,管理器面板
- nginx nginx "--with-ipv6" option is deprecated 问题
- hiawatha服务器反向代理配置的一些坑
- nginx: [emerg] Solution to unknown directive "set_real_ip_from"
- 一款可视化适合小白的cdn构建系统
- 重新编译nginx,以便支持最新的quic(http3)以及 brotli 压缩