V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
hakr
V2EX  ›  问与答

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

  •  
  •   hakr · 2023-01-16 14:56:43 +08:00 · 630 次点击
    这是一个创建于 465 天前的主题,其中的信息可能已经有所发展或是发生改变。
    因为只有一个域名, 所以想使用 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 条回复    2023-01-17 10:51:54 +08:00
    rrfeng
        1
    rrfeng  
       2023-01-16 15:02:53 +08:00
    nginx 不认识盘符。用相对路径吧。
    sss15
        2
    sss15  
       2023-01-16 15:08:13 +08:00
    愚见,把 alias 换成 root 试试
    hakr
        3
    hakr  
    OP
       2023-01-16 15:08:29 +08:00
    @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  
       2023-01-16 16:15:36 +08:00
    alias "D:/soft/phpstudy_pro/WWW/www.sc-one.com/sc-admin"
    jifengg
        5
    jifengg  
       2023-01-17 08:45:04 +08:00
    我的 windows nginx 配置路径也遇到过,用了 \\ 代替 / 是 ok 的。
    另外,你 404 也要看看 nginx error log ,看看它访问资源的路径是啥
    hakr
        6
    hakr  
    OP
       2023-01-17 10:51:54 +08:00
    @sss15 #2
    @fly0512 #4
    @jifengg #5
    搞定了 try_files 那里改成了 try_files $uri $uri/ /sc-admin/index.html;
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5701 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 06:27 · PVG 14:27 · LAX 23:27 · JFK 02:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.