1
wzxjohn 2014-05-19 14:19:16 +08:00 1
分别在8080和8081端口监听,然后在80端口开启反向代理服务器,根据域名选择后端端口即可。
|
2
zoowii 2014-05-19 14:19:24 +08:00 1
nginx反代
|
3
leohxj OP |
4
hging 2014-05-19 15:07:57 +08:00
upstream test {
server 0.0.0.0:3000; } server { root /home/rongyi/project/rongyi_term1/public; index index.html index.htm; server_name 192.168.1.56; location / { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_buffering on; proxy_pass http://test; } error_page 404 /404.html; error_page 500 502 503 504 /500.html; } @leohxj |
5
hging 2014-05-19 15:09:12 +08:00 1
server_name你写你的域名 然后第二行server里面写你程序的端口. 多个的话,复制多个这个配置,然后把upstream后面的名字还有下面的proxy_pass 这个都修改下就行了.
|
6
rrfeng 2014-05-19 15:12:38 +08:00 1
upstream server1 { server 127.0.0.1:8080}
upstream server2 { server 127.0.0.1:8081} server { listen 80; server_name SERVER_NAME_1 SERVER_NAME_2; location / { if ( $server_name == server1 ) { proxy_pass http://server1; } if ( $server_name == server 2 ) { proxy_pass http://server2; } } |
7
leohxj OP @hging
我试了你的这段内容,没有起效。 我自己这样写的代理: server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { listen 80; server_name 192.168.1.60; location ~ / { proxy_pass http://localhost:3000; proxy_set_header Host $host:80; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Via "nginx"; } } 能通过192.168.1.60访问到192.168.1.60:3000,但是CSS,JS文件响应都很慢。 我就是想在本地上实现一个localhost转发到4000端口,192.168.1.60转发到3000端口的功能。 |
8
leohxj OP @rrfeng
@leohxj 可以帮我看下我刚刚上面写的那种方式,为什么资源文件响应都很慢? 按照你们的方式,我这样写之后,速度正常了: upstream nodejs__upstream { server 127.0.0.1:3000; keepalive 64; } server { listen 80; server_name 192.168.1.60; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_set_header Connection ""; proxy_http_version 1.1; proxy_pass http://nodejs__upstream; } } 谢谢! |
10
peneazy 2017-01-11 16:04:13 +08:00
学到一手
|