linux服务器配置nginx


1、拷贝nginx的代理配置;
2、更换pid文件路径;
改为:/run/nginx.pid
3、添加nginx用户;
groupadd nginx
useradd -s /sbin/nologin -g nginx nginx
4、更换日志文件目录;
改为:/var/log/nginx/error.log
改为:/var/log/nginx/项目名.access.log
5、添加systemctl服务;
cd /usr/lib/systemd/system
vim nginx.service

[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true

[Install]
WantedBy=multi-user.target

 

6、生效nginx.service
sudo systemctl daemon-reload

7、启动nginx服务;
检查nginx.service路径:sudo systemctl status nginx
启动nginx.service:sudo systemctl start nginx

posted @ 2021-10-20 17:00  这里有个bug啊  阅读(143)  评论(0)    收藏  举报