【问题标题】:How to remove the port number from URL in a nginx site如何从 nginx 站点中的 URL 中删除端口号
【发布时间】:2020-03-02 02:24:30
【问题描述】:

在 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;
  }

}

【问题讨论】:

  • 向我们展示一个示例,说明您的 nginx 配置如何匿名个人/站点数据,以便我们知道发生了什么。
  • 如果您的服务器正在侦听端口 8000,那么您无法从 URL 中隐藏它。如果您不想显示端口号,则需要配置服务器,使其侦听标准端口(80 或 443)。
  • @flaixman 我已经添加了。
  • 你没有80或443端口的配置吗?
  • 没有。我必须使用8000端口。我的主要问题是,为什么 Python 内置的 Web 服务器不显示 URL 中的端口,但 nginx 显示?

标签: linux unix nginx webserver nginx-config


【解决方案1】:

我才发现

port_in_redirect off;

解决了。

【讨论】:

    猜你喜欢
    • 2021-11-20
    • 2020-02-20
    • 2015-10-21
    • 2016-02-06
    • 2014-07-18
    • 2011-07-04
    • 2014-12-18
    相关资源
    最近更新 更多