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


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

  • @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. Oct 20, 2012 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. Oct 20, 2012 at 15:07
  • Are you using Google Chrome? Would you see 400 when using Firefox?
    – lulalala
    Oct 26, 2012 at 9:32

2 Answers 2


This is probably a typo:

            try_files $uri =400;

It should almost certainly be:

            try_files $uri =404;

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.

Source: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-14-04

  • 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, 2015 at 0:19
  • @Paul I hope the changes I made is sufficient. Thanks for the information. Nov 26, 2015 at 16:39

You must log in to answer this question.