3

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;
}
1
  • 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
    – Mike
    Jun 8, 2017 at 18:58

1 Answer 1

8

I found this over on the nginx wiki

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .