hakr
V2EX  ›  问与答

请问这个 nginx 配置问题出在哪里

  •  
  •   hakr · Jan 16, 2023 · 1245 views
    This topic created in 1235 days ago, the information mentioned may be changed or developed.
    因为只有一个域名, 所以想使用 nginx 代理二级目录, index 文件在 D:\soft\phpstudy_pro\WWW\ww.sc-one.com\sc-admin\index.html



    配置文件

    server {
    listen 9003;
    server_name _;

    location /sc-admin {
    alias "D:/soft/phpstudy_pro/WWW/www.sc-one.com/sc-admin/";
    try_files $uri $uri/ index.html;
    index index.html;
    }
    }



    但是访问 localhost:9003/sc-admin 404 请问是哪里有问题
    6 replies    2023-01-17 10:51:54 +08:00
    rrfeng
        1
    rrfeng  
       Jan 16, 2023
    nginx 不认识盘符。用相对路径吧。
    pushMeUp
        2
    pushMeUp  
       Jan 16, 2023
    愚见,把 alias 换成 root 试试
    hakr
        3
    hakr  
    OP
       Jan 16, 2023
    @rrfeng #1 应该不是盘符的问题, 改成下面这样后又出现了 500 Internal Server Error 错误

    server {
    listen 9003;
    server_name _;
    root "D:/soft/phpstudy_pro/WWW/www.sc-one.com";
    location /sc-admin {
    alias "D:/soft/phpstudy_pro/WWW/www.sc-one.com/sc-admin/";
    try_files $uri $uri/ /sc-admin/index.html;
    index index.html;
    }
    }
    fly0512
        4
    fly0512  
       Jan 16, 2023
    alias "D:/soft/phpstudy_pro/WWW/www.sc-one.com/sc-admin"
    jifengg
        5
    jifengg  
       Jan 17, 2023
    我的 windows nginx 配置路径也遇到过,用了 \\ 代替 / 是 ok 的。
    另外,你 404 也要看看 nginx error log ,看看它访问资源的路径是啥
    hakr
        6
    hakr  
    OP
       Jan 17, 2023
    @sss15 #2
    @fly0512 #4
    @jifengg #5
    搞定了 try_files 那里改成了 try_files $uri $uri/ /sc-admin/index.html;
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1106 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 18:27 · PVG 02:27 · LAX 11:27 · JFK 14:27
    ♥ Do have faith in what you're doing.