I want to make use of the alias function in NGINX to accomplish something simple. I have searched the internet for the last 3 days and found nothing but bad or outdated examples and was hoping someone could post a working example based on a newer version of NGINX.

I have the following url:


My question is how do I make NGINX forward this request to the internal user folder:


...and return its index.php page?

Please keep in mind that this index.php page is passed to the php FastCGI server listening on

1 Answer 1


Funny, I had the same problem finding useful information about apache style aliasing or script aliasing. I ended up blogging about it the other day.

This was tested with nginx version 1.0.5, but should work on 0.85 also.

server {
    listen 80;
    server_name localhost;
    index index.html index.php;
    root /var/www;
    location ~ ^/username_123(.*)\.php($|/) {
        include php_fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /var/www/html/profiles/username_123$1.php;
    location ~ ^/username_123(.*) {
        autoindex on;
        alias /var/www/html/profiles/username_123$1;

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.