我在使用以下启动命令时遇到 NGINX 行为不同的问题:
brew services start nginx
对比
sudo nginx
当我使用 启动 nginx 时sudo nginx
,一切似乎都正常工作。但是当我尝试使用 启动 nginx 时brew service start nginx
,如果我加载在使用 之前加载的页面sudo nginx
,它会启动并正常工作,但任何新内容都不会加载。我必须sudo nginx
先使用 来加载该页面。
brew services list
显示 nginx 已启动,但状态为黄色
Name Status User Plist
nginx started usera /Users/usera/Library/LaunchAgents/homebrew.mxcl.nginx.plist
php71 started usera /Users/usera/Library/LaunchAgents/homebrew.mxcl.php71.plist
这是我的nginx.conf
文件
user usera admin;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
# Include Configuration
#include conf.d/*.conf;
# Include Enabled Sites
include sites-enabled/*;
include servers/*;
}
default
服务配置文件
server {
listen 8080;
server_name default.localhost;
location / {
root html/default;
index index.html index.htm;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
答案1
nginx
需要以 root 身份执行才能访问所有必要的资源。它可以配置为以非 root 身份运行。
sudo
或者,也可以使用以下命令运行brew services
:
sudo brew services start nginx