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 just setup nginx on my Ubuntu staging machince. Entering http://192.168.1.1./index.php works like a charm and loads the index.php file i've put in the /var/www/public_html folder. http://192.168.1.1 however instead shows the Welcome to nginx! page and not my index.php file.

What am I doing wrong? Here's my nginx config:

server {

    listen 80 default;
    root /var/www/public_html;
    index index.php index.html index.htm;
    server_name _;

    location / {
        try_files $uri $uri/ /index.html;
    }

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}
share|improve this question
    
You're sure that you have no other sites in sites-enabled that might be conflicting? –  pauska Aug 16 '11 at 17:15
    
BTW: Weird config with rewrites and custom fastcgi_param's, are you using some kind of howto or application specific guide? –  pauska Aug 16 '11 at 17:17
    
No other sites in either sites-enabled or sites-available! –  Industrial Aug 16 '11 at 17:32

2 Answers 2

up vote 0 down vote accepted

Looking at the documentation for try_files: http://wiki.nginx.org/HttpCoreModule#try_files, you probably should have something like:

location / {
    try_files $uri $uri/ /index.html /index.php;
}

Take a look at the examples for Drupal, Wordpress, FastCGI, etc.

share|improve this answer
    
Hi cjc. I tried both to append try_files inside my location / as well as outside of it. No change –  Industrial Aug 16 '11 at 19:47
    
Did you use /index.php as the last argument? –  cjc Aug 16 '11 at 19:56
    
Yep! ` location / { try_files $uri $uri/ /index.php; } ` –  Industrial Aug 16 '11 at 20:00
    
The other suggested thing was to have "try_files $uri $uri/ @php;" and then a @php location block with your FCGI configuration. –  cjc Aug 16 '11 at 20:05

I'm guessing that you still have the default site config in sites-enabled, and that it's alphabetically sorted higher than your custom config. The default config will catch any request without known host headers, and use index.html as index.

share|improve this answer
    
Hi Pauska. unfortunately not - deleted the default and reloaded & restarted multiple times since :( –  Industrial Aug 16 '11 at 17:32
    
No difference with or without the custom fastcgi_params inside the ` location ~ \.php`-section –  Industrial Aug 16 '11 at 17:56

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.