nginx running but not rendering html or php

Hello all, this is my first post on this fine forum. :)

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

Did you reload/restart nginx after adding the server config(s)?

Create a symbolic link in /etc/nginx/sites-enabled and reload nginx :

cd /etc/nginx/sites-enabled

ln -s /etc/nginx/sites-available/mysite.com ./

/etc/init.d/nginx reload

Restarting nginx did it, thanks.

Now the html renders, but no luck processing my php. Now to find the cause of this…

Thanks petar & sleddog.

Several things to check:

4. Is php-fpm running? Check using the command (without quotes): "ps aux | grep fpm"

  1. Does your nginx vhost include index.php as a possible index?

  2. Is your nginx vhost configured with a php location block?

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

Hi Piki.

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

Go it working! It was just a matter of adding the index.php to the location index, not just the location ~ .php$ fastcgi_index.

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.

Ok, I'll move the index directive outside, as I'm planning on hosting several sites on this Linode.

Could you point to a guide on installing php-fpm with nginx? I just seem to find fcgi guides on the Linode Library.

This could be what you are looking for, assuming that you are using Ubuntu. If not, you can most probably find a proper tutorial at the site, lots of good stuff there.

Since I don't know your distro, I can't point you to any guides (they tend to be distro-specific). Finding them is relatively easy using Google, search "how to set up nginx and php-fpm on centos" (replace centos with your distro).

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.

  1. Install php-fpm (it might be called php5-fpm by your distro).

  2. Open the php-fpm config file, locate the listen line, and make sure it's set to 127.0.0.1:9000

  3. 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/www.conf.

EDIT: If you're using Debian, you may wish to use Dotdeb. They provide slightly newer server packages (Nginx, PHP, etc.) than the official Debian repos, and they work fairly well.

Nice, thorough answers. I appreciate the time given.

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.

By the way, my distro is Ubuntu.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct