【问题标题】:Nginx sub-path shows 404 errorNginx子路径显示404错误
【发布时间】:2016-07-27 22:02:57
【问题描述】:

我正在尝试设置 nginx 以使用子路径,但我收到 404 错误。我正在使用默认位置和 html 文件。

Nginx 配置如下:

server {
  listen 80;
  listen[::]:80 ipv6only=on;
  server_name localhost;

  ## serving gogs
  location / {
    proxy_pass http://localhost:3000;
  }

  ## serving laravel-based web app
  location /yt/ {
    root /usr/share/nginx/html;
    index index.html index.htm;
  }
}

防火墙 (ufw) 已禁用,所有端口均通过 mikrotik 打开。打开 / 路径时一切正常,但转到 /yt/ 时出现 404 错误。

【问题讨论】:

    标签: nginx


    【解决方案1】:

    不确定配置是否正确,当我与我的本地简单设置进行比较时,我发现它几乎没有什么不同。如果可行,请尝试此方法。

    server {
      listen 80;
      listen[::]:80 ipv6only=on;
      server_name localhost;
    
      ## serving gogs
      location /yt/ {
        proxy_pass http://localhost:3000/;
        proxy_redirect off;
        proxy_set_header Host $host;
      }
    }
    

    【讨论】:

    • 其实问题是我没有在nginx的html文件夹中创建子文件夹。只是查看了错误日志并找到了它。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 2020-03-19
    • 2021-11-15
    • 2019-08-27
    • 2016-06-24
    • 2015-09-21
    • 2017-02-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多