0

So I am new to NGINX, and I am trying to setup a simple phpinfo page in /home/codehitman/nginx/phpinfo directory. I have setup the /etc/hosts file with the following directive:

127.0.0.1    phpinfo.local

And here is the conf file:

server {
    listen 80;
    server_name  phpinfo.local;

    root   /home/codehitman/nginx/phpinfo;

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

    location / {
        index index.php;
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_pass  localhost:9000;
        fastcgi_param SCRIPT_FILENAME
                      $document_root$fastcgi_script_name;
        include       fastcgi_params;
    }
}

The virtual host file has been softlinked to the sites-enabled folder and the server has been restarted with a [OK]. But whenever I go to the page I keep seeing the default nginx page. I don't see the log files being generated but if I tail the default logs then I see this:

127.0.0.1 - - [02/Jan/2016:22:03:20 -0500] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0"

When I inspect the headers in the browser's developer tools, then I see a GET request for / and not phpinfo.local. I have also changed the ownership and permissions to the nginx directory in my home directory:

sudo chown -R www-data:www-data /home/codehitman/nginx
sudo chmod -R 777 /home/codehitman/nginx

Could someone please tell me what I am doing wrong? Cheers!

EDIT: So I figured out the reason why this wasn't working the first time. I had softlinked it wrong. Now that it is linked correctly, I am getting a 502 Bad gateway error with this in the log:

2016/01/02 22:52:36 [error] 18653#0: *16 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: phpinfo.local, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "phpinfo.local"
3
  • Remove the default configuration and try tailing the error log. Everything looks right there to me.
    – Ashley
    Jan 3, 2016 at 3:30
  • Okay figured out why I was getting the 304s in the log. I didn't softlink correctly. Instead of ln -s /etc/nginx/sites-available/phpinfo sites-enabled, I did ln -s sites-available/phpinfo ... from the nginx directory.
    – codehitman
    Jan 3, 2016 at 3:55
  • Your problem now is probably in your php-fpm conf. You might want to edit the question to include that info.
    – Ashley
    Jan 3, 2016 at 3:58

1 Answer 1

0

Solved it! I had to replace the .php with this:

location ~ .php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

Also make the following changes to the default virtualhost:

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

    # With php5-cgi alone:
    #       fastcgi_pass 127.0.0.1:9000;
    # With php5-fpm:
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
}

I got the answer here: https://stackoverflow.com/a/15854491/3199478

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .