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 am trying to run a website (that requires PHP - it technically doesn't require MySQL at this time, but it may sometime in the near future as I continue developing it, so I went ahead and installed that as well) using nginx 1.2.4 and PHP-FPM 5.3.3 on Ubuntu 12.04.1 LTS. As far as I know, I haven't done anything wrong, but clearly something is not quite right - I seem to be getting a 400 Bad Request error whenever I try to browse to my website. I've been mostly following one guide, and I've done more or less everything it recommends, except for not setting up PHP-FPM to use a Unix Socket and I used service as opposed to /etc/init.d/ when starting/stopping nginx, PHP, and MySQL.

Anyways, here are my relevant configuration files (I have only censored personal/sensitive details, like my domain name - which contains my real name):

/etc/nginx/nginx.conf

user www-data;
worker_processes 4;
pid /var/run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 15;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # nginx-naxsi config
        ##
        # Uncomment it if you installed nginx-naxsi
        ##

        #include /etc/nginx/naxsi_core.rules;

        ##
        # nginx-passenger config
        ##
        # Uncomment it if you installed nginx-passenger
        ##

        #passenger_root /usr;
        #passenger_ruby /usr/bin/ruby;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

/etc/nginx/sites-enabled/subdomain.mydomain.net

server {
        listen 80;      # listen for IPv4
        listen [::]:80; # listen for IPv6

        server_name www.subdomain.mydomain.net subdomain.mydomain.net;

        access_log /srv/www/subdomain.mydomain.net/logs/access.log;
        error_log /srv/www/subdomain.mydomain.net/logs/error.log;


        location / {
                root /srv/www/subdomain.mydomain.net/public;
                index index.php;
        }


        location ~ \.php$ {
                try_files $uri =400;
                include fastcgi_params;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /srv/www/subdomain.mydomain.net/public$fastcgi_script_name;
        }
}

All the directories listed in the configuration files above are correct on my server (to the extent of my knowledge).

I have not included /etc/php5/fpm/pool.d/www.conf or /etc/php5/fpm/php.ini in this post as they're rather long, but I have posted them on Pastebin: http://pastebin.com/ensErJD8 and http://pastebin.com/T23dt7vM, respectively. Although, the only thing I've changed in either of the two files was in php.ini, where I set expose_php to off so as to hide the .php file extension from users.

What can I do to resolve my issue? Please let me know if I need to supply any additional details.

share|improve this question

migrated from superuser.com Oct 20 '12 at 11:23

This question came from our site for computer enthusiasts and power users.

    
@Bob: I commend you for using PHP-FPM + Nginx, it's the most efficiant PHP stack. As for using a local TCP connection, rather than a PHP-FPM socket, I would only go that route when such connections come over the network. It's always less efficiant, and socket configuration is fairly minimal. The simplified conclusion, unless you have mitigating circumstances, always follow best practices. –  TechZilla Oct 20 '12 at 15:04
    
@Bob: Additionally if fixing that '400-404' typo fails to fix the situation, please provide some tailed log files. Specifically nginx, and PHP-FPM, error logs. –  TechZilla Oct 20 '12 at 15:07
    
Are you using Google Chrome? Would you see 400 when using Firefox? –  lulalala Oct 26 '12 at 9:32
add comment

1 Answer

This is probably a typo:

            try_files $uri =400;

It should almost certainly be:

            try_files $uri =404;
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.