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

When browsing to a page on the site the page is being download instead of running Nginx Config -

    user www-data www-data;
worker_processes  4;
events {
    worker_connections  2048;
http {
    include       mime.types;
    default_type  application/octet-stream;
    access_log  off;
    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay     off;
    keepalive_timeout  10;
    gzip  on;
    gzip_comp_level 2;
    gzip_proxied any;
    gzip_types      text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root  /home/bil/public_html/;
            index  index.html index.htm;
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
include /usr/local/nginx/sites-enabled/*;


Virtual Site config -

server {
            listen   80;
            server_name  localhost;
            rewrite ^/(.*)$1 permanent;
server {
            listen   80;
            server_name localhost;
            access_log /home/bil/public_html/;
            error_log /home/bil/public_html/;
            location /  {
                        root  /home/bil/public_html/;
                        index  index.php index.html;
            # pass the PHP scripts to FastCGI server listening on
            location ~ \.php$
            fastcgi_index index.php;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
            include /usr/local/nginx/conf/fastcgi_params;
            fastcgi_param SCRIPT_FILENAME /home/bil/public_html/$fastcgi_script_name;

share|improve this question

I don't think your server_name's are reflecting what you want to do. The configuration is fine, but all three "localhost" mean the first one catches. There is no php location in the first one.

share|improve this answer

Replace your rewrite rule with below

rewrite ^/(.*)$1 last;

I Hope this will help, Thanks

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.