linux - systemctl启动nginx没有加载nginx.conf配置文件?
高洛峰
高洛峰 2017-04-17 14:00:28
0
2
1031

fedora23 ,我在我的用户目录下面放了我的工程文件夹,其中有一些静态文件(css,图片之类的),就用nginx做了个服务器来提供。
nginx是用的fedora wiki上面nginx教程里提供的方法直接从fedora源用dnf安装的,装好后nginx.conf里面配置的用户是“nginx”。不管我怎么改变我用户目录的权限,总之就是403 forbidden,查看log显示权限不够。

看了网上的教程,说开发中直接使用root用户即可,想想很有道理,就把nginx.conf里面的用户改成了root,重启nginx 服务后查看ps aux | grep nginx, 发现确实是root用户了,然而仍然是403

后来我直接使用nginx -c /etc/nginx/nginx.conf来启动,就一切正常了。使用ps aux查看用户没有区别,只有master process这一项由/usr/sbin/nginx变成了nginx -c /etc/nginx/nginx.conf

现在的猜测是,systemctl启动(包括service nginx start这种方式)启动的时候并没有正确加载nginx.conf中关于用户的配置项,但是server的配置是正常的……

不知道有没有人遇到和我一样的问题

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
大家讲道理

It turns out that the permission management of SElinux is causing trouble. It does not allow nginx to access nginx.conf. You can directly google nginx. You can find the method on the nginx official website for selinux. Just use semanage plus httpd_t or something. Just google for details

Peter_Zhu

I also encountered such a problem. I installed it using yum install nginx, and nginx.service was automatically generated after installation. But using systemctl start nginx.service will get stuck. After using ctrl + C to end, check that the process has been started and can be used normally. If you can start it with /usr/sbin/nginx -c /etc/nginx/nginx.conf, there will be no such problem. I suspect that there is a problem with the systemctl startup file. After checking, the most likely problem is ExecStartPre=/usr/ sbin/nginx -t -c /etc/nginx/nginx.conf

view /usr/lib/systemd/system/nginx.service

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss -lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf I put This line blocks
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID

[Install]
WantedBy=multi-user.target

There is no problem if you execute /usr/sbin/nginx -t -c /etc/nginx/nginx.conf alone, but there is a problem if you put it here. Although the problem is solved, I still don’t understand why this happens. kind of problem.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!