1

On my linux PC, I'd like to run nginx as whatever user I'm logged into when I start it, and I'd like it to look for config files in the home directory of that user.

Is there a way to install nginx to do this instead of always running as the same user (e.g. the nginx user) and looking to some config directory in /etc or /usr?

1

Of course there is.

You create a nginx.conf file in your home directory with similar content (replace [USERNAME] by your login):

error_log /home/[USERNAME]/nginx.log;
pid        /home/[USERNAME]/nginx.pid;

http {
    include  /etc/nginx/mime.types;
    index   index.php;
    client_body_temp_path /home/[USERNAME]/tmp;
    proxy_temp_path /home/[USERNAME]/tmp;
    fastcgi_temp_path /home/[USERNAME]/tmp;
    uwsgi_temp_path /home/[USERNAME]/tmp;
    scgi_temp_path /home/[USERNAME]/tmp;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for" "$http_cookie" "$sent_http_content_type"';

    access_log  /home/[USERNAME]/nginx-access.log  main  buffer=32k;

    gzip  on;

    server {
        listen       1234;
        server_name  server.example.com;
        root    /home/[USERNAME]/public_html;
        index index.php;

        ... 
    }
}

And then run /usr/sbin/nginx -c /home/[USERNAME]/nginx.conf - it will start server for your user. Remember that only root can bind to ports below 1024 (i.e. 80). You will have to configure the server to listen on some other port.

0

If the configuration folders are hard-coded, (meaning no command line parameters available to change them), you'll have to compile it yourself and change the parameters using --prefix etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.