Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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