Running Nginx as a user without root

I installed Nginx using Ansible. For installation on Centos7, I used the yum package, so it was launched as the root user by default. I want it to start and run as another user (ex-nginx user) in the Centos field. When I try to run it with another user, I get the following error:

Work for nginx.service failed, because the management process ended with an error code. See "Systemctl nginx.service Status" and "journalctl -xe" for details.

I know that it is not recommended to run as root. So, how do I get around this and run nginx as a user without root. Thanks

+4
source share
1 answer

Add / change the following to /etc/nginx/nginx.conf:

user nginx;

You must create user replicas and grant permissions for web court directories.

Thus, only the master process works like root. Because: Only root processes can listen on ports below 1024. The web server usually runs on port 80 and / or 443. This means that it must be run with root privileges.

To start the master process as a user without root:

Change 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 listening directives to ports above 1024, log in as a user and run nginx on nginx -c /path/to/nginx.conf

+6
source

Source: https://habr.com/ru/post/1670228/


All Articles