Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've set up Nginx to handle all my static files else proxy_pass to a Node.js server. It's working fine but I'm having difficulty rewriting the url so that it remove the .html file extension.

upstream my_upstream {
        server 127.0.0.1:8000;
        keepalive 64;
}


server {
        listen       80;
        server_name  staging.mysite.com;
        root /var/www/staging.mysite.org/public;

        access_log /var/logs/staging.mysite.org.access.log;
        error_log /var/logs/staging.mysite.org.error.log;

        location ~ ^/(images/|javascript/|css/|robots.txt|humans.txt|favicon.ico) {

            rewrite (.*)\.html $1 permanent;
            try_files  $uri.html  $uri/ /index.html;

            access_log off;
            expires max;
        }   

        location / {

                proxy_redirect off;
                proxy_set_header   X-Real-IP            $remote_addr;
                proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
                proxy_set_header   X-Forwarded-Proto $scheme;
                proxy_set_header   Host                   $http_host;
                proxy_set_header   X-NginX-Proxy    true;
                proxy_set_header   Connection "";
                proxy_http_version 1.1;
                proxy_cache one;
                proxy_cache_key sfs$request_uri$scheme;
                proxy_pass         http://my_upstream;
        }
}
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

I came up with this. And it seems to be working so far.

location / {
  try_files $uri $uri/ $uri.html @node;
}
location @node {
  proxy_pass http://127.0.0.1:3000;
}
share|improve this answer
add comment

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.