Running Nginx as non root user

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

    Add/Change the following in your /etc/nginx/nginx.conf:

    user nginx;
    

    You should create the user and grant permissions on the webroot directories recursively.

    This way only master process runs as root. Because: Only root processes can listen to ports below 1024. A webserver typically runs at port 80 and/or 443. That means it needs to be started as root.

    To run master process as non root user:

    Change the ownership of the following:

    • error_log
    • access_log
    • pid
    • client_body_temp_path
    • fastcgi_temp_path
    • proxy_temp_path
    • scgi_temp_path
    • uwsgi_temp_path

    Change the listen directives to ports above 1024, log in as desired user and run nginx by nginx -c /path/to/nginx.conf

提交回复
热议问题