Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

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;
share|improve this answer

Your Answer


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.