【发布时间】:2018-11-27 19:50:04
【问题描述】:
我正在通过 brew 使用 nginx,它似乎已配置并正常工作 - 在一定程度上。我有多个主机文件(大约 20 个站点),几乎所有这些文件都可以正常工作,但是,添加的任何新站点都将无法正常工作。
所有旧主机文件似乎都可以正常加载,例如在端口 80 上使用服务器名称 site.test,但添加的任何新主机文件在我的网络浏览器中返回“找不到服务器”。
经过多次故障排除和 Google 搜索,我终于在我的设置中发现了一些奇怪的东西,正是这篇文章触发了它:nginx.conf and nginx.pid users and permissions。虽然它似乎并没有解决我的确切问题。
当我运行nginx -t 时,我得到:
nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/etc/nginx/nginx.conf:1
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: [emerg] open() "/usr/local/var/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /usr/local/etc/nginx/nginx.conf test failed
但是,当我运行 sudo nginx -t 时,我得到:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
我已经杀死了 nginx 并使用 brew 优雅地停止它并使用 sudo 重新启动它,但我似乎遇到了与 nginx.pid 相同的问题。
当我启动 nginx 时,我使用:sudo brew services start nginx
运行ps aux | grep nginx,返回:
Media32 7444 0.0 0.0 4339424 2016 ?? S 12:16pm 0:00.01 nginx: worker process
Media32 7443 0.0 0.0 4339424 1836 ?? S 12:16pm 0:00.00 nginx: worker process
root 7440 0.0 0.0 4297440 4876 ?? Ss 12:16pm 0:00.01 nginx: master process /usr/local/opt/nginx/bin/nginx -g daemon off;
这应该是正确的,因为我的用户在 nginx.conf 中设置为user Media32 staff。
我可以提供任何其他必要的代码,但我已经为此不知所措好几天了,我们将不胜感激。
更新
我似乎已经通过编辑/etc/hosts 并为新主机文件添加记录来解决这个问题,即。 127.0.0.1 site.test 然后在重新加载 nginx 之后它就可以工作了,但是我以前从来没有这样做过,任何人都可以解释为什么需要这样做并且之前不需要这样做吗?
【问题讨论】:
-
我认为应该与您的更新无关。这是您的计算机解析主机的方式。只需将 nginx 服务器指向 127.0.0.1。
标签: nginx