nginx.conf and nginx.pid users and permissions

前端 未结 2 1957
萌比男神i
萌比男神i 2021-02-14 17:06

I\'m embarking on watching my NGINX error.log files at level: warn... probably a silly idea and will cause me to crash my server as I work out any bugs happening, but hey, we\'r

相关标签:
2条回答
  • 2021-02-14 17:20

    I got the same error on my Centos 7 server today.

    nginx.pid" failed (13: Permission denied)

    For me, it turned out to be a problem with SELinux. I did the following to make it work again:

    systemctl stop nginx
    touch /var/run/nginx.pid
    chcon -u system_u -t httpd_var_run_t /var/run/nginx.pid
    systemctl start nginx
    

    running

    ls -Z nginx.pid
    

    should output

    -rw-r--r--. root root system_u:object_r:httpd_var_run_t:s0 nginx.pid

    0 讨论(0)
  • 2021-02-14 17:20

    In my case I got a

        "/usr/local/var/run/nginx.pid" failed (13: Permission denied)
    
        bind() to 0.0.0.0:80 failed (48: Address already in use)
    

    and the working solution was made up of these steps:

    1. stop root process

      sudo nginx -s stop
      
    2. check if process stopped

      ps aux | grep nginx
      
    3. restart process

      sudo nginx -s reload
      

    gave me the error

        nginx: [error] open() “/usr/local/var/run/nginx.pid” failed (2: No such file or directory)
    

    probabil .pid was started with the wrong root user as I uncommented the line with path to .pid in /usr/local/etc/nginx/nginx.conf and then I commented it back again

    1. to start nginx as a user and not root

      brew services start nginx
      
    2. result at running command

      ps aux | grep nginx
      
      youruser 89212 0.0 0.0 4268280 644 s002  S+ 2:46PM 0:00.00 grep nginx
      youruser 89179 0.0 0.0 4302204 1776 ?? S 2:45PM 0:00.00 nginx: worker process  
      youruser 89178 0.0 0.0  4275372 4368 ?? S 2:45PM 0:00.01 nginx: master process /usr/local/opt/nginx/bin/nginx -g daemon off;
      

    And as it can be seen, the nginx process started with the expected user and not as root and the conflict between processes was gone and I could access the PHP application local domain.

    0 讨论(0)
提交回复
热议问题