Nginx 正向代理
# vim /etc/nginx/conf.d/site.conf
server {
listen 8000;
charset utf-8;
location /static {
alias /home/zheng/Documents/Project/INFO/static/;
}
location / {
uwsgi_max_temp_file_size 0;
uwsgi_pass 0.0.0.0:9000;
include /etc/nginx/uwsgi_params;
}
}
# nginx -s reload
Nginx 反向代理
server {
listen 80;
charset utf-8;
client_max_body_size 75M;
location /static { # 配置静态文件访问
alias /home/zheng/djangotest/static;
}
location / { # 单个个代理服务器
proxy_pass http://192.168.43.230:8000;
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-Nginx-Proxy true;
}
}
nginx -s reload
### 代理多个服务器
```nginx
# vim /etc/nginx/conf.d/site.conf
server {
listen 80;
charset utf-8;
client_max_body_size 75M;
location /static { # 配置静态文件访问
alias /home/zheng/djangotest/static;
}
location /python { # 第一个代理服务器
proxy_pass http://192.168.43.230:8000;
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-Nginx-Proxy true;
}
location /java { # 第二个代理服务器
proxy_pass http://192.168.43.231:8000;
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-Nginx-Proxy true;
}
}
# nginx -s reload
Nginx 负载均衡
# vim /etc/nginx/conf.d/site.conf
upstream mynginx { # 反向代理的域名(多个--负载均衡)
server 192.168.43.230:19000;
server 192.168.43.231:19000;
}
server {
listen 80;
charset utf-8;
client_max_body_size 75M;
location /static { # 配置静态文件访问
alias /home/zheng/djangotest/static;
}
location / { # 配置反向代理
proxy_pass http://mynginx;
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-Nginx-Proxy true;
}
}
# nginx -s reload
问题
用Nginx做反向代理的时候,配置静态文件
- 把静态文件放在Nginx服务器上
- 静态资源的访问直接通过Nginx来获取
- 动态请求再转发到web服务器。
评论区