首页 > 解决方案 > 如何从 nginx 站点中的 URL 中删除端口号

问题描述

在 URL 中,我看到如下内容:http://example.com:8000/page. 即使我设法通过在没有端口的情况下键入 URL 来访问该站点,但当我转到任何子页面时,它也会添加到那里。

我曾经有一个基于 Python 的 Web 服务器而不是 nginx,它工作得非常好,但是,端口号从来没有出现过。这就是为什么我仍然希望有一种方法可以隐藏非标准端口(无需将其更改为标准端口),因为 Python Web 服务器没有显示。

顺便说一下,我重定向端口 80 >> 8000。

nginx 配置中是否有隐藏站点的非标准端口的功能?如果没有,也许还有其他方法?

我的配置:

server {

  listen 8000;

  access_log /logs/access.log;
  error_log /logs/error.log;

  index index.html;
  server_name example.com;

  error_page 404 errors/404.html; 

  location / {
    try_files $uri $uri/ =404;
  }

}

标签: linuxunixnginxwebservernginx-config

解决方案


我刚刚想通了

port_in_redirect off;

解决它。


推荐阅读