Switch to NginX

Discussion in 'General' started by dclardy, Nov 23, 2011.

  1. dclardy

    dclardy Member

    Is it possible to switch from Apache to NginX? It seems like this should be able to be done without having to reinstall the entire system.
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    If none of your websites uses apache rewrite rules or .htaccess files or any other apache specific features, then it might be possible to migrate a system.
     
  3. dclardy

    dclardy Member

    I have switched over to NginX the hard way at this point, but there is an issue with the PHP setup. I am using the DotDeb packages for Debain.

    Here is the error in the log for the site:

    Code:
    2011/11/24 08:26:12 [error] 8099#0: *11 connect() to unix:/var/lib/php5-fpm/web1.sock failed (111: Connection refused) while connecting to upstream, client: 96.226.233.87, server: drewclardy.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/lib/php5-fpm/web1.sock:", host: "drewclardy.com"
    Any ideas on how to fix this issue? What is the fastcgi:// part that is there?
     
  4. dclardy

    dclardy Member

    Any other ideas on this guys? I have been messing with it all day. From what I can see nginx can't connect to the socket. I have tried not using the socket, but that fails as well.
     
  5. falko

    falko Super Moderator Howtoforge Staff

    Are permissions of /var/lib/php5-fpm/web1.sock ok?
     
  6. dclardy

    dclardy Member

    They are set to the website iser and group.

    web1 client1
     
  7. dclardy

    dclardy Member

    I am almost certain that there is an error with the way that the configuration files are being written for the NginX vhost. If you look at a vhost file that is written by the system, you find something like this:

    Code:
    server {
            listen *:80;
    
    
            server_name minecraftarea.com www.minecraftarea.com;
    
            root   /var/www/minecraftarea.com/web;
    
    
    
            index index.html index.htm index.php index.cgi index.pl index.xhtml;
    
    
    
            error_page 400 /error/400.html;
            error_page 401 /error/401.html;
            error_page 403 /error/403.html;
            error_page 404 /error/404.html;
            error_page 405 /error/405.html;
            error_page 500 /error/500.html;
            error_page 502 /error/502.html;
            error_page 503 /error/503.html;
    
            error_log /var/log/ispconfig/httpd/minecraftarea.com/error.log;
            access_log /var/log/ispconfig/httpd/minecraftarea.com/access.log combined;
    
            ## Disable .htaccess and other hidden files
            location ~ /\. {
                deny all;
                access_log off;
                log_not_found off;
            }
    
            location = /favicon.ico {
                log_not_found off;
                access_log off;
            }
    
            location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
            }
    
            location /stats {
                index index.html index.php;
                auth_basic "Members Only";
                auth_basic_user_file /var/www/clients/client1/web3/.htpasswd_stats;
            }
    
            location ~ \.php$ {
                try_files $uri =404;
                include /etc/nginx/fastcgi_params;
                fastcgi_pass 127.0.0.1:9012;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_script_name;
                fastcgi_intercept_errors on;
            }
    
    
    
    
    }
    This does not allow the site to load from what I can tell. I was able to get the site to work properly by changing some of the configuration.

    I had to remove the error document lines, and I had to put the different type of index lines into a location.

    Code:
    server {
            listen *:80;
    
    
            server_name drewclardy.com www.drewclardy.com;
    
            root   /var/www/drewclardy.com/web;
    
            error_log /var/log/ispconfig/httpd/drewclardy.com/error.log;
            access_log /var/log/ispconfig/httpd/drewclardy.com/access.log combined;
    
    
            location / {
    
            index index.html index.htm index.php index.cgi index.pl index.xhtml;
            try_files $uri $uri/ /index.php;
    
            }
    
            ## Disable .htaccess and other hidden files
            location ~ /\. {
                deny all;
                access_log off;
                log_not_found off;
            }
    
            location = /favicon.ico {
                log_not_found off;
                access_log off;
            }
    
            location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
            }
    
            location /stats {
                index index.html index.php;
                auth_basic "Members Only";
                auth_basic_user_file /var/www/clients/client1/web1/.htpasswd_stats;
            }
    
            location ~ \.php$ {
                try_files $uri =404;
                include /etc/nginx/fastcgi_params;
                fastcgi_pass unix:/var/lib/php5-fpm/web1.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_script_name;
                fastcgi_intercept_errors on;
            }
    
    
    }
    
    These changes allowed NginX to load the site that it was giving the connection error to before hand.

    I am pretty sure that this is a critical bug!
     
  8. falko

    falko Super Moderator Howtoforge Staff

Share This Page