NGINX:如何在一台服务器或域名中设置多个端口 [英] NGINX: How to setup multiple port in one server or domain name
问题描述
大家好,我是nginx的新手.我的设置遇到问题,我希望服务器在公共端口上运行多个端口.
Hi Guys I am new to nginx,. I am having trouble with my setup, I want my server to run with multiple port on public.
例如:
server {
listen 443 ssl;
server_name <https - mydomainname>;
ssl_certificate <location cert>;
ssl_certificate_key <location key>;
location /tags.txt {
add_header 'Access-Control-Allow-Origin' '*';
}
}
通过上述设置,我现在可以正常访问了.但是如果我有 http://localhost:6006 和 http://localhost:5005 我的localhost中有多个端口,我想发布它.我尝试使用此https-mydomainname:端口6006和https-mydomainname:端口5005访问它,但失败.
From the above setup I am now able to access perfectly. But what if I have http://localhost:6006 and http://localhost:5005 multiple ports in my localhost and I want to publish it. I tried to access it using this https - mydomainname : port 6006 and https - mydomainname : port 5005 but it fails.
我应该为另一个端口进行设置吗? 就像端口6006一样
Should I make a setup for another port? Like for port 6006
server {
listen 6006 ssl;
server_name <https - mydomainname>;
ssl_certificate <location cert>;
ssl_certificate_key <location key>;
location /tags.txt {
add_header 'Access-Control-Allow-Origin' '*';
proxy_pass http://localhost:6006;
}
}
和端口5005
server {
listen 5005 ssl;
server_name <https - mydomainname>;
ssl_certificate <location cert>;
ssl_certificate_key <location key>;
location /tags.txt {
add_header 'Access-Control-Allow-Origin' '*';
proxy_pass http://localhost:5005;
}
}
我不知道该如何解决.任何帮助都非常感谢.
I have no idea how to fix this. Any help is very appreciated thanks.
推荐答案
每个server
可以有多个listen
指令:
server {
listen 5005 ssl;
listen 6006 ssl;
server_name <https - mydomainname>;
ssl_certificate <location cert>;
ssl_certificate_key <location key>;
location /tags.txt {
add_header 'Access-Control-Allow-Origin' '*';
}
}
这篇关于NGINX:如何在一台服务器或域名中设置多个端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!