Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
 Post subject: Nginx not working
PostPosted: Thu Nov 03, 2011 9:30 pm 
Offline
Newbie

Joined: Thu Nov 03, 2011 8:49 pm
Posts: 4
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:
Code:
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:
Code:
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:
Code:
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


Top
   
 Post subject:
PostPosted: Thu Nov 03, 2011 9:38 pm 
Offline
Senior Member

Joined: Fri May 02, 2008 8:44 pm
Posts: 1121
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?
Code:
/etc/init.d/nginx restart

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


Top
   
 Post subject: Nginx not working
PostPosted: Fri Nov 04, 2011 8:46 am 
Offline
Newbie

Joined: Thu Nov 03, 2011 8:49 pm
Posts: 4
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
Code:
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:

Code:
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


Top
   
 Post subject:
PostPosted: Fri Nov 04, 2011 8:59 am 
Offline
Senior Member

Joined: Sun Mar 07, 2010 7:47 pm
Posts: 1970
Website: http://www.rwky.net
Location: Earth
Try replacing it with
Code:
/sbin/start-stop-daemon

_________________
Paid support
How to ask for help
1. Give details of your problem
2. Post any errors
3. Post relevant logs.
4. Don't hide details i.e. your domain, it just makes things harder
5. Be polite or you'll be eaten by a grue


Top
   
 Post subject: nginx Not working
PostPosted: Fri Nov 04, 2011 9:45 am 
Offline
Newbie

Joined: Thu Nov 03, 2011 8:49 pm
Posts: 4
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


Top
   
 Post subject:
PostPosted: Fri Nov 04, 2011 10:11 am 
Offline
Senior Member

Joined: Fri May 02, 2008 8:44 pm
Posts: 1121
Try removing the "try_files $uri =404" line from the FastCGI block. I've never seen "try_files" 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!


Top
   
PostPosted: Fri Nov 04, 2011 6:47 pm 
Offline
Newbie

Joined: Thu Nov 03, 2011 8:49 pm
Posts: 4
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


Top
   
 Post subject:
PostPosted: Fri Nov 04, 2011 11:10 pm 
Offline
Senior Member
User avatar

Joined: Thu Jun 16, 2011 8:24 am
Posts: 412
Location: Cyberspace
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/fastcgi_params, and for your "location ~ \.php$" just put include /etc/nging/fastcgi_params" (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.

_________________
Kris the Piki Geeker


Top
   
 Post subject:
PostPosted: Mon Nov 07, 2011 4:34 am 
Offline
Senior Member

Joined: Sat Nov 13, 2010 3:05 am
Posts: 91
Website: http://www.graq.co.uk
hybinet wrote:
Try removing the "try_files $uri =404" line from the FastCGI block. I've never seen "try_files" 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


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group