Home  >  Q&A  >  body text

Could you please help me check if there is anything that needs to be changed in this nginx.service file?

After compiling and installing nginx on centos7.2, you need to write a nginx.service file so that you can use systemctl enable nginx.service. Here is an example of mysqld http: //superuser.com/a/384670/577295
I wrote an imitation, but some parameters are not sure whether they are correct or not. Please check it.

    [Unit]
    Description=Nginx Server
    After=network.target
    
    [Service]
    ExecStart=/usr/local/nginx/sbin/nginx --defaults-file=/usr/local/nginx/conf/nginx.conf  --socket=/var/run/nginx/nginx.sock
    User=nginx
    Group=nginx
    WorkingDirectory=/usr
    
    [Install]
    WantedBy=multi-user.target

Question:
1. Is there anything that needs to be changed?
2. Is there anything missing?
3, --socket=/var/run/nginx/nginx.sockIf you don’t have this file, if you write it yourself, what should be in it?

The following are the relevant paths for compilation and installation:

sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
    -e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \
    -e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \
    -e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
    < man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/root/nginx-1.9.14'
我想大声告诉你我想大声告诉你2713 days ago462

reply all(2)I'll reply

  • 世界只因有你

    世界只因有你2017-05-16 17:19:57

    I am a newbie, here is how I solved this problem. First install Nginx with yum, and then check the compilation options of Nginx, mainly the directory options. Then download the source code yourself, set the relevant compilation options to the ones you just viewed, and finally replace the yum-installed executable file with the compiled nginx executable file. This eliminates the need to write those service scripts. Typing on the phone is messy.

    reply
    0
  • PHPz

    PHPz2017-05-16 17:19:57

    Please don’t copy it mechanically
    nginx does not have --defaults-file or --socket parameter
    You can’t just use cp *.service nginx.service

    Official examples have been given
    https://www.nginx.com/resources/wiki/sta...

    [Unit]
    Description=The NGINX HTTP and reverse proxy server
    After=syslog.target network.target remote-fs.target nss-lookup.target
    
    [Service]
    Type=forking
    PIDFile=/run/nginx.pid
    ExecStartPre=/usr/sbin/nginx -t
    ExecStart=/usr/sbin/nginx
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/bin/kill -s QUIT $MAINPID
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target

    reply
    0
  • Cancelreply