Running Nginx as non root user

前端 未结 3 782
爱一瞬间的悲伤
爱一瞬间的悲伤 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:21

    Just in case it helps someone stumbling over this question in 2020, here is my minimal nginx.conf for running a web server on port 8088, works for a non-root user. No modding of file permissions necessary! (Tested on Centos 7.4 with nginx 1.16.1)

        error_log /tmp/error.log;
        pid       /tmp/nginx.pid;
        
        events {
          # No special events for this simple setup
        }
        http {
          server {
            listen       8088;
            server_name  localhost;
        
            # Set a number of log, temp and cache file options that will otherwise
            # default to restricted locations accessible only to root.
            access_log /tmp/nginx_host.access.log;
            client_body_temp_path /tmp/client_body;
            fastcgi_temp_path /tmp/fastcgi_temp;
            proxy_temp_path /tmp/proxy_temp;
            scgi_temp_path /tmp/scgi_temp;
            uwsgi_temp_path /tmp/uwsgi_temp;
        
            # Serve local files
            location / {
              root /home//web;
              index  index.html index.htm;
              try_files $uri $uri/ /index.html;
            }
          }
        }
    

提交回复
热议问题