Nginx配置转发
Posted 大厨的笔记
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx配置转发相关的知识,希望对你有一定的参考价值。
1. cd到/usr/local/nginx/conf/
找到 nginx.conf 配置文件文件
以下代码为配置代码
其中upstream 的backwww 要对应server.location下面的proxy_pass
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream backwww { #ip_hash;
#项目对应的端口号 server 127.0.0.1:8000; } upstream backa { #ip_hash; server 127.0.0.1:8001; } upstream backb { #ip_hash; server 127.0.0.1:8002; } server { listen 80;
#项目的访问地址 server_name www.chenzhanghui.vip; location / { 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_buffering off; proxy_pass http://backwww; } } server { listen 80;
#项目的访问地址 server_name a.chenzhanghui.vip; location / { 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_buffering off; proxy_pass http://backa; } } server { listen 80; server_name b.chenzhanghui.vip; location / { 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_buffering off; proxy_pass http://backb; } } }
以上是关于Nginx配置转发的主要内容,如果未能解决你的问题,请参考以下文章