nginx running but not rendering html or php
Just installed nginx and php fast cgi on my linode. Everything was going fine, nginx seems to be up and running but my domain is not rendering a simple hello world html file on it.
All I get when visiting my site is the standard 'welcome to nginx' message.
On the bash every install went smoothly, I followed all the guides.
Is this a config issue I have to resolve ?
I've just added the server config to:
/etc/nginx/sites-available/mysite.com
as per the guide. I haven't touched the:
/etc/nginx/nginx.conf
12 Replies
cd /etc/nginx/sites-enabled
ln -s /etc/nginx/sites-available/mysite.com ./
/etc/init.d/nginx reload
Now the html renders, but no luck processing my php. Now to find the cause of this…
Thanks petar & sleddog.
4. Is php-fpm running? Check using the command (without quotes): "ps aux | grep fpm"
Does your nginx vhost include index.php as a possible index?
Is your nginx vhost configured with a php location block?
Does your php location block have "include fastcgi_params" or "include fastcgi.conf" without quotes? (look in /etc/nginx to see which one to use)
EDIT: If all of those are true, please paste the vhost file. Make sure click the Code button near the top of the forum's Reply screen, and ensure that the vhost appears between the code tags that appear.
Responses:
1. Yes.
2. It includes it under fastcgi_index , not index.
3. Yes.
4. Its has "include fastcgi_params", which is correct I believe.
My virtual host file, where "mysite.com" is my actual domain:
server {
server_name www.mysite.com mysite.com;
access_log /srv/www/mysite.com/logs/access.log;
error_log /srv/www/mysite.com/logs/error.log;
root /srv/www/mysite.com/public_html;
location / {
index index.html index.htm;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/mysite.com/public_html$fastcgi_$
}
}
UPDATE: Now, attempting to restart fast cgi gives me:
spawn-fcgi: bind failed: Address already in use
Thanks for your time and help.
Now, is that error while attempting a fast cgi restart to be expected ?
The "spawn-fcgi: bind failed: Address already in use" error.
@EduardoV5:
Go it working! It was just a matter of adding the index.php to the location index, not just the location ~ .php$ fastcgi_index.
That is needed for most cases since fastcgiindex and index are not the same thing. fastcgiindex is specific to cgi wrappers such as fcgi or php-fpm, where index is global to the entire vhost.
@EduardoV5:
Thanks for your time and help.
Now, is that error while attempting a fast cgi restart to be expected ?
The "spawn-fcgi: bind failed: Address already in use" error.
You shouldn't be seeing that error, however I've seen many people report issues with using php directly through fcgi (instead of php-fpm. Far fewer problems seem arise from using php-fpm, so it may be worth switching, if only just to try it and see if it works. Just make sure fcgi isn't running when you start php-fpm.
Quick tip: This isn't really necessary, but it's generally good to keep the index directive outside location blocks. This way, if you decide to place subdirectories in your vhost's root which also contain one of the index options you specify, nginx will automatically use it when visiting the subdirectory.
Better yet, if all your vhosts will use the same index line, place it in your nginx.conf instead, in the http section.
Could you point to a guide on installing php-fpm with nginx? I just seem to find fcgi guides on the Linode Library.
This
Here are some generic instructions, use your distro's package manager to install/remove stuff:
4. Remove the fcgi package that the Linode Library had you install.
Install php-fpm (it might be called php5-fpm by your distro).
Open the php-fpm config file, locate the listen line, and make sure it's set to 127.0.0.1:9000
Restart both php-fpm and nginx and see if it works.
Finding the php-fpm config file should be easy, just search through the /etc directory. Likely possibilities are /etc/php.ini, /etc/php/php.ini, or /etc/php/php-fpm.conf. Some distros (Debian included) put the listen line in a separate file, e.g. /etc/php/fpm/pool.d/
EDIT: If you're using Debian, you may wish to use Dotdeb
If I make the change over to fpm from fcgi, I'll make another thread detailing whether the former produces less errors, or none at all.