NGINX:如何在一台服务器或域名中设置多个端口? [英] NGINX: How to setup multiple port in one server or domain name?

查看:188
本文介绍了NGINX:如何在一台服务器或域名中设置多个端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 nginx 的新手.我的设置有问题,我希望我的服务器在多个公共端口上运行.

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' '*';
    }
}

通过上述设置,我现在可以访问 <https - mydomainname>完美.但是如果我的本地主机中有 http://localhost:6006 和 http://localhost:5005 多个端口并且我想发布它怎么办.我尝试使用此 https - mydomainname :端口 6006 和 https - mydomainname :端口 5005 访问它,但它失败了.

From the above setup I am now able to access <https - mydomainname> 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;
  }
}

如何解决?

推荐答案

您可以为每个 server 设置多个 listen 指令:

You can have multiple listen directives per server:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆