2

I'm a nginx noob and am looking for some help (my nginx config is below). I'm attempting to put nginx in front of a PHP application that currently uses Apache.

my "/" location is working properly. Nginx is serving the static files and proxying to apache for the dynamic content.

I'm now trying to make "UserDir" functionality work properly. I need http://example.com/~mmattax/ to use /home/mmattax/public_html as the document root and proxy to apache for the dynamic content. My attempt below seems to proxy everything to apache; nginx does not seems to be using the correct document root.

I'm also looking for any tips on the config below. Thanks.

location ~ ^/~(.+?)(/.*)?$ {
    root /home/$1/public_html;
    index  index.php;
    autoindex on;
    try_files $uri $uri/ @proxy;
}

location / {
    root  /home/myapp/www;
    index index.php;
    try_files $uri $uri/ @proxy;
}

location @proxy {
    proxy_pass http://127.0.0.1:8080;
    proxy_redirect off;
}

location ~ \.php$ {
    proxy_pass      http://127.0.0.1:8080;
    proxy_redirect  off;
}
  • did you ever figure out how to make this dynamic? I am trying to do the same thing through Gunicorn on a python stack and am having a real hard time finding information about how to set it up – Turk Jun 8 '17 at 18:58
5

I found this over on the nginx wiki

location ~ ^/~(.+?)(/.*)?$ {
 alias /home/$1/public_html$2;
 index  index.html index.htm;
 autoindex on;
}
  • This is the same regex that I'm using, but I'm wanting to proxy dynamic content. – mmattax Nov 1 '11 at 22:08

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.