我在这里写这个是因为网上似乎没有关于这个问题的一致性,而且我还认为有一些我不知道的标准做法,所以如果有人能启发我那就太好了。
我正在尝试在 MacOS 上运行基本的 nginx 配置。
我的 nginx 目录(包含我的 nginx.conf)位于:
/usr/local/etc/nginx
同时,我要提供的 index.html 文件位于:
/usr/local/var/www/index.html
这些是 homebrew 在安装 Nginx 时给我的目录路径。
我的 nginx conf 如下所示:
3 events {
4 worker_connections 1024;
5 }
6
7 http {
8 server {
9
10 index index.html index.htm;
11
12 location / {
13 root /var/www;
14 }
15 }
16 }
这是我在教程(包括官方的 nginx 教程)上看到的,但我很困惑为什么根目录中的 /var/www 不是我机器根目录的相对路径。我试过使用相对路径、这条路径和其他变体,并不断得到 404。如果有人可以 a) 解释路径问题和 b) 告诉我哪里出错了,我会非常感激。每次更改 conf 时,我都会使用 sudo nginx -s reload 重新加载 nginx。
对于 /usr/local/var/www/index.html 中的项目,您应该将 nginx 根参数设置为:
root /usr/local/var/www/
root参数是项目文件夹的绝对路径。您还应该指定要公开的端口,通常是端口 80。
服务器块可能是这样的:
server {
listen 80 ;
server_name mysite.com ;
index index.html index.htm;
location / {
root /usr/local/var/www ;
# other opts here
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句