账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    nginx用域名访问时location配置失效
    68
    0

    下面是配置部分,location配置了/file/匹配时,访问/test/files/目录的静态文件。测试用ip访问可以正常下载文件,但是用域名的时候似乎没有生效,请求反向代理到tomcat去处理了,然后返回404.

    server
      {
        listen     80;
        server_name host.com;
        root  /var/www/html;
        proxy_ignore_client_abort on;
    
        #limit_conn   crawler  20;
    
        location ^~ /file/ {
            alias  /test/files/;
        }
    
        location / {
               proxy_set_header X-real-ip $remote_addr;
               proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
               proxy_set_header  Host $http_host;
               proxy_pass http://tomcat_svr;
        }
    }
    1
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • Nginx默认使用/作为主机名,如果你想在域名中添加/index.html,你可以使用以下配置:

      nginx location /index.html { try_files $uri $uri/ =404; }

      这将尝试使用默认的404页面来处理/index.html的请求。如果你的404页面是一个其他的位置,你可以修改try_files$uri参数,例如:

      nginx location /index.html { try_files $uri $uri/ /index.html; }

      这将尝试使用/index.html页面来处理请求。请注意,这将覆盖默认的404页面。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部