Nginx将IP:PORT重定向到域名

时间:2019-03-28 08:08:28

标签: nginx redirect

我的Web服务器在端口4000上运行,并且我已配置nginx以使用域名通过HTTPS提供服务。我的应用程序和配置运行良好,但该应用程序也正在使用SERVER_PUBLIC_IP:<PORT>来处理请求。我在配置中添加了一个额外的服务器组件,该配置可以成功将SERVER_PUBLIC_IP请求重定向到域名,但是无法将SERVER_PUBLIC_IP:4000重定向到域名。

下面是nginx配置:

server {
  gzip on;
  gzip_comp_level    6;
  gzip_types application/javascript text/css text/plain application/json;
  gzip_min_length 1000;

  root /var/www/html;

  # Add index.php to the list if you are using PHP
  index index.html index.htm index.nginx-debian.html;

  listen 80;

  listen 443 ssl;

  ssl on;
  ssl_certificate /etc/nginx/ssl/domain.crt; 
  ssl_certificate_key /etc/nginx/ssl/domain.key;

  server_name my.domain.com;

  location / {
    proxy_pass http://localhost:4000/;
  }
}

server {
  listen 80 default_server;
  listen [::]:80 default_server;
  server_name 13.250.13.202;
  return 301 https://my.domain.com;
}

我想对其进行配置,以便它也用IP:4000重定向请求。我尝试在下面添加内容,但不起作用。

server {
  listen 4000;
  listen [::]:4000 ipv6only=on;
  server_name 13.250.13.202:4000;
  return 301 https://my.domain.com;
}

这会导致错误:

Mar 28 07:59:36 ip-172-31-11-93 nginx[29637]: nginx: [emerg] bind() to 0.0.0.0:4000 failed (98: Address already in use)

我不知道该尝试哪种方法。任何帮助将不胜感激!

0 个答案:

没有答案
相关问题