我有一个旧的服务器设置,我已经通过端口420给人们提供服务的url,example.corp.com:420,现在我将所有服务移动到Ngnix中的常规80端口,我希望所有请求到来从example.corp.com:420到默认返回example.corp.com。有没有办法告诉Ngnix去app1而不管给出的端口号?我尝试了一些东西,但都没有用。这是我目前的配置。提前谢谢。
upstream unicorn-app1 {
server unix:/tmp/unicorn.app1.sock;
}
server {
listen 80;
server_name example.corp.com;
root /home/example/apps/wm/current/public;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://unicorn-app1;
break;
}
}
}
upstream unicorn-app2{
server unix:/tmp/unicorn.app2.sock;
}
server {
listen 420;
server_name example.corp.com;
root /home/example/apps/app2/current/public;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://unicorn-app2;
break;
}
}
}
答案 0 :(得分:0)
我实际上已经开始工作了。当你明白发生了什么事情时,我认为这很简单,我只是错过了整个工作所必需的小细节。因此,每当您需要将Ngnix服务器的不同端口默认返回到特定端口时,您所要做的就是将其他端口应用定义为指向80端口应用。这是解决方案,我大胆地提出了必须改变以使其工作的内容。希望它有所帮助。
upstream unicorn-app1 {
server unix:/tmp/unicorn.app1.sock;
}
server {
listen 80;
server_name example.corp.com;
root /home/example/apps/wm/current/public;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://unicorn-app1;
break;
}
}
}
upstream unicorn-app2{
server unix:/tmp/unicorn.**app1**.sock;
}
server {
listen 420;
server_name example.corp.com;
root /home/example/apps/**app1**/current/public;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://unicorn-**app1**;
break;
}
}
}
答案 1 :(得分:0)
实际上更好的方法是让端口420重定向到端口80,这样人们就会慢慢停止使用端口480,只需使用301重定向
server {
listen 480;
server_name example.com;
return 301 example.com$request_uri;
}