nginx的新手
我有一项服务,但有两个版本-旧版本和新版本
http://old.somedomain.com -> old_server:3000
http://new.somedomain.com -> new_server:3000
nginx配置
server {
listen 80;
server_name old.somedomain.com;
location / {
proxy_pass http://old_server:3000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 80;
server_name new.somedomain.com;
location / {
proxy_pass http://new_server:3000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
主机文件
<old_server ip> old.somedomain.com
<new_server ip> new.somedomain.com
它工作很好,但是此解决方案需要添加两行-<ip> <domain>
每次都要在每个人的PC上托管文件!是否可以简化这种情况?
http://somedomain.com/old -> old_server:3000
http://somedomain.com/new -> new_server:3000
或http://somedomain.com -> new_server:3000
只需要向主机文件添加一行!
我尝试了这个nginx配置,但是没有用。(当然它不起作用,看起来像sh * t!)
server {
listen 80;
server_name somedomain.com;
location /old {
proxy_pass http://old_server:3000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location / {
proxy_pass http://new_server:3000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
所以我的想法可能吗?有更好的解决方案吗?