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

2023-01-16 14:56:43 +08:00
 hakr
因为只有一个域名, 所以想使用 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 请问是哪里有问题
634 次点击
所在节点    问与答
6 条回复
rrfeng
2023-01-16 15:02:53 +08:00
nginx 不认识盘符。用相对路径吧。
sss15
2023-01-16 15:08:13 +08:00
愚见,把 alias 换成 root 试试
hakr
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
2023-01-16 16:15:36 +08:00
alias "D:/soft/phpstudy_pro/WWW/www.sc-one.com/sc-admin"
jifengg
2023-01-17 08:45:04 +08:00
我的 windows nginx 配置路径也遇到过,用了 \\ 代替 / 是 ok 的。
另外,你 404 也要看看 nginx error log ,看看它访问资源的路径是啥
hakr
2023-01-17 10:51:54 +08:00
@sss15 #2
@fly0512 #4
@jifengg #5
搞定了 try_files 那里改成了 try_files $uri $uri/ /sc-admin/index.html;

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/909276

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX