安装Nginx
http://nginx.org/en/linux_packages.html#RHEL-CentOS
配置Nginx
nginx.conf 文件可能在以下目录:/usr/local/nginx/conf
, /etc/nginx
, or /usr/local/etc/nginx
配置域名代理,可以在conf.d目录中添加
分别配置
# saas.conf server { listen 80; server_name saas-export-manager.xxx.net; location / { proxy_pass http://127.0.0.1:8080; } } # saas-manager.conf server { listen 80; server_name saas-export.xxx.net; location / { proxy_pass http://127.0.0.1:8081; } }
配置反向代理
server{ listen 8001; server_name 10.202.203.29; location / { proxy_pass http://10.200.80.21; } } server{ listen 8002; server_name localhost; location / {proxy_pass http://10.200.151.28;} }
访问http://10.202.203.29:8001 打开10.200.80.21
访问http://10.202.203.29:8002 打开10.200.151.28
还可以配置有端口的
server { listen 80; location / { proxy_pass http://localhost:5000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $http_host; proxy_cache_bypass $http_upgrade; } }
这样的话80端口的访问都会转发到5000端口
负载均衡
server{ listen 8001; server_name 10.202.203.29; location / { proxy_pass http://backend; } } upstream backend { server 10.200.151.28; server 10.200.80.21; }