Nginx not working

Hi,

I just got a fresh installation of Debian Squeeze as my Linode partition. I installed nginx + php. I configured both as indicated in the Linode wiki for LEMP installation (http://library.linode.com/lemp-guides/debian-6-squeeze). I add small test script in index.html and index.php file on my root website directory. When I try to access my website, I get the following response:

http://myipaddress ==> connection failed

http://myipaddress/index.html ==> connection failed

http://myipaddress/index.php ==> connection failed

I checked the log: there is no log (both nginx and website logs)

Is nginx working?

I checked the processes. Here is what I got:

root@li60-86:~# ps -aux | grep nginx
nginx     1540  0.0  1.0  18632  5144 ?        Ss   20:41   0:00 /usr/bin/php5-cgi
nginx     1547  0.0  0.3  18632  1868 ?        S    20:41   0:00 /usr/bin/php5-cgi
nginx     1548  0.0  0.3  18632  1868 ?        S    20:41   0:00 /usr/bin/php5-cgi
nginx     1549  0.0  0.3  18632  1868 ?        S    20:41   0:00 /usr/bin/php5-cgi
nginx     1550  0.0  0.3  18632  1868 ?        S    20:41   0:00 /usr/bin/php5-cgi
nginx     1551  0.0  0.3  18632  1868 ?        S    20:41   0:00 /usr/bin/php5-cgi
nginx     1552  0.0  0.3  18632  1868 ?        S    20:41   0:00 /usr/bin/php5-cgi
root      1631  0.0  0.1   3352   724 pts/0    S+   20:59   0:00 grep nginx

I'm newbie with Debian + nginx + PHP-cli but not with Ubuntu + Apache + mod_php5. It's like if nginx was not running. I have created some day ago an Ubunu oneiric + nginx + PHP-cli and it was worked fine. Now, with Debian, it seem like ngix doesn't work or like if port 80 was locked.

Here is my nginx website config:

server {

        listen   80; ## listen for ipv4
        #listen   [::]:80 default ipv6only=on; ## listen for ipv6

        server_name  myipaddress;

        access_log  /var/www/myipaddress/logs/access.log;

        error_log  /var/www/myipaddress/logs/error.log;

        location / {
                root /var/www/myipaddress/public_html;
                index  index.html index.htm index.php;
        }

        location /doc {
                root   /usr/share;
                autoindex on;
                allow 127.0.0.1;
                deny all;
        }

        location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
                access_log      off;
                expires         30d;
                root    /var/www/myipaddress/public_html;
        }

        location /images {
                root   /usr/share;
                autoindex on;
        }

        #error_page  404  /404.html;

        # redirect server error pages to the static page /50x.html
        #
        #error_page   500 502 503 504  /50x.html;
        #location = /50x.html {
        #       root   /var/www/nginx-default;
        #}
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
                #proxy_pass   http://127.0.0.1;
        #}

        # 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)(.*)$;
                fastcgi_pass   backend;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /var/www/[i]myipaddress[/i]/public_html$fastcgi_script_name;
                include /etc/nginx/fastcgi_params;
                fastcgi_param   CONTENT_TYPE    $content_type;
                fastcgi_param   CONTENT_LENGTH  $content_length;
                fastcgi_intercept_errors        on;
                fastcgi_ignore_client_abort     off;
                fastcgi_connect_timeout 60;
                fastcgi_send_timeout    180;
                fastcgi_read_timeout    180;
                fastcgi_buffer_size     128k;
                fastcgi_buffers 4 256k;
                fastcgi_busy_buffers_size       256k;
                fastcgi_temp_file_write_size    256k;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
                deny  all;
        }
}

upstream backend {
        server  127.0.0.1:9000;
}

and fastcgi_params is:

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

Somebody has any idea?

Thanks

8 Replies

nginx doesn't seem to be running at all. Did you use the official version or did you follow the compile instructions? The compile instructions seem to be outdated, and you shouldn't be compiling your own web server on a stable Debian box anyway.

Try this command. Do you get any errors?

/etc/init.d/nginx restart

Also see /var/log/nginx/error.log for any nginx errors.

Hi,

The problem I found is the init nginx script in /etc/init.d I use to start it. I installed nginx apt package and I use the compile init script given in the documentation of Linode.

I modified the path of nginx from /opt/nginx to /usr/sbin. When I start the daemon by hand with

sudo /usr/sbin/nginx

it's fine. But when I try to start it with the modified init script, I got a "start-stop-daemon command not found". I reproduce here the section of the script who is not working:

start)
        echo -n "Starting $DESC: "
        start-stop-daemon --start --quiet --pidfile /var/www/myipaddress/logs/$NAME.pid \
                --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --quiet --pidfile /var/www/myipaddress/logs/$NAME.pid \
                --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
restart|force-reload)
        echo -n "Restarting $DESC : "
        start-stop-daemon --stop --quiet --pidfile /var/www/myipaddress/logs/$NAME.pid \
                --exec $DAEMON -- $DAEMON_OPTS
        start-stop-daemon --start --quiet --pidfile /var/www/myipaddress/logs/$NAME.pid \
                --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;

Could you tell me by which command I have to replace "start-stop-daemon"?

Thanks

Try replacing it with /sbin/start-stop-daemon

Hi,

Thank you for your advice. It fixes my nginx init script. Now, nginx is working for .html file. But when I try to access .php script, file is not parsed by php runtime. The script appears as pure text in my browser! Could you check my nginx file and tell me what I have to do to fix it? php5-cgi and php5-cli are installed from apt packages.

Thanks

Try removing the "tryfiles $uri =404" line from the FastCGI block. I've never seen "tryfiles" inside FastCGI blocks.

BTW, I don't know where you're pulling those init scripts and config files from, but they just look wrong in my opinion. What are all those fastcgi config lines doing in the middle of a virtual host definition? Debian comes with reasonable defaults, and I know what those defaults looks like. Those files you're using were definitely not shipped with Debian. No wonder they don't work well when mixed with Debian packages. Expect more surprises!

Hi,

Yes, I mixed Debian aptitude packages with Linode scripts. I was following a Linode tutorial… I also confused php-cgi with php-fpm. Then while trying to fix my website, I installed php-fpm above php-cgi and added some new entries from my last Ubuntu distribution (read from a tutorial on a web site) in my nginx configuration.

I tried to go back, but it was too late. So, I decided to scrapt my Linode partition and start from scratch with a fresh new Debian distribution. It took me a while to fixe some minor problems. Now, my website is on line and PHP is working well.

Thank you for your help

Just a tip, unless a specific virtual host requires special settings for your "location ~ .php$", just keep all of your fastcgi settings in /etc/nginx/fastcgiparams, and for your "location ~ .php$" just put include /etc/nging/fastcgiparams" (no quotes), that will just make nginx pull all your settings from fastcgi_params and include them in your php location block. It'll reduce the clutter. Anything you can do to reduce redundancy and clutter and be more organized is (in most cases) better.

@hybinet:

Try removing the "tryfiles $uri =404" line from the FastCGI block. I've never seen "tryfiles" inside FastCGI blocks.
This is a security configuration to stop the uploading and executing of malicious PHP code posing as an alternate file type. It does not stop fastCGI from working.

EDIT: Here's a related nginx forum post: http://forum.nginx.org/read.php?2,88845,page=3

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