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"