Running Nginx as non root user

前端 未结 3 781
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-24 08:46

I installed Nginx using Ansible. To install on Centos7 I used the yum package so it by default was run as root user. I want it to start and run as a different user

3条回答
  •  感动是毒
    2020-12-24 09:30

    Just in case it helps, for testing/debugging purpose, I sometimes run an nginx instance as a non privileged user on my Debian (stretch) laptop.

    I use a minimal config file like this:

    worker_processes 1;
    error_log stderr;
    daemon off;
    pid nginx.pid;
    
    events {
      worker_connections  1024;
    }
    
    http {
      include             /etc/nginx/mime.types;
      default_type        application/octet-stream;
    
      sendfile on;
    
      keepalive_timeout   65;
    
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
      ssl_prefer_server_ciphers on;
      access_log access.log;
      server {
        listen            8080;
        server_name       localhost;
    
        location / {
          include /etc/nginx/uwsgi_params;
          uwsgi_pass localhost:8081;
        }
      }
    }
    

    and I start the process with:

    /usr/sbin/nginx -c nginx.conf -p $PWD
    

提交回复
热议问题