Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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'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 {
        keepalive 64;

server {
        listen       80;
        root /var/www/;

        access_log /var/logs/;
        error_log /var/logs/;

        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
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 {
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.