我正在尝试创建多个应用程序,在具有一个 IP 地址(没有域名、子域)的一台服务器上监听不同的端口。
应用程序A监听80端口,
应用程序B监听8080端口
我想通过
http//xxx.xxx.xxx.xxx:80
和分别访问两个应用程序http//xxx.xxx.xxx.xxx:8080
如果我有域名,我可以创建多个子域,并像这样配置 nginx:
server {
server_name A.domain.com;
listen 80;
root someplace/;
try_files /maintenance.html $uri $uri.html @puma;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header Client-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http//xxx.xxx.xxx.xxx:80;
}
}
server {
server_name B.domain.com;
listen 80;
root someplace/;
try_files /maintenance.html $uri $uri.html @puma;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header Client-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http//xxx.xxx.xxx.xxx:8080;
}
}
如果我没有域名,是否可以
http//xxx.xxx.xxx.xxx:80
通过http//xxx.xxx.xxx.xxx:8080
像这样吗?
server {
server_name xxx.xxx.xxx.xxx;
listen 80;
root someplace/;
try_files /maintenance.html $uri $uri.html @puma;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header Client-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http//xxx.xxx.xxx.xxx:80;
}
}
server {
server_name xxx.xxx.xxx.xxx;
listen 8080;
root someplace/;
try_files /maintenance.html $uri $uri.html @puma;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header Client-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http//xxx.xxx.xxx.xxx:8080;
}
}