Sign up ×
Server Fault is a question and answer site for 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):


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

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/*;


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


        access_log /srv/www/;
        error_log /srv/www/;

        location / {
                root /srv/www/;
                index index.php;

        location ~ \.php$ {
                try_files $uri =400;
                include fastcgi_params;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /srv/www/$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: and, 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 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

2 Answers 2

This is probably a typo:

            try_files $uri =400;

It should almost certainly be:

            try_files $uri =404;
share|improve this answer

I'm guessing TechZilla already stated this, but you could modify this line:


to be this.

fastcgi_pass unix:/var/run/php5-fpm.sock;

I was assuming because you stated you installed PHP-FPM, that the using the .sock method should be better than passing on through TCP.

Connecting to PHP-FPM through the .sock method can be done if the package installing PHP-FPM also sets the necessary permissions and configured correctly. If not, you may have to resort to connecting to PHP-FPM through Thanks to Paul for informing me on that.

It is also possible that this line:

include fastcgi_params;

could be changed into this:

include fastcgi.conf;

However, don't count me on this. I have no clue why this works on my Ubuntu Server VM, but it does at the moment.


share|improve this answer
PHP-FPM will need to be configured to run at that socket with appropriate user and group permissions. It isn't always packaged that way. – Paul Nov 26 at 0:19
@Paul I hope the changes I made is sufficient. Thanks for the information. – user2442110 Nov 26 at 16:39

Your Answer


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