question regarding the Nginx Catch-All Host As Front End To Apache For ISPConfig3 tut

Discussion in 'HOWTO-Related Questions' started by Ovidiu, Oct 15, 2010.

  1. Ovidiu

    Ovidiu Active Member

    deleted, accidental double post :-(
     
    Last edited: Nov 3, 2010
  2. Ovidiu

    Ovidiu Active Member

    ok,that worked. the last step is to get an exception worked into the config file for domains that use wordpress with multisite enabled where wildcard subdomains are used.

    the errors look like:

    the problem is nginx is looking for /var/www/adi.zice.ro/web/ which does nto exist. adi.zice.ro is a virtual subdomain handled by wordpress.

    so basically I need to extend this:
    so that if $host is stripped of www and any subdomains and the resulting $host is zice.ro these rewrite rules are executed as zice.ro is multisite enabled with virtual subdomains:
    any help out there?
     
  3. Ovidiu

    Ovidiu Active Member

    something along the lines of:
    :)
     
  4. Ovidiu

    Ovidiu Active Member

    ok, I figured it out. I have one default nginx config that catches all vhosts except the one that is running wp with subdomains (multisite enabled). that one has its own config file.
    It all works but I had to copy these rewrites from here for the wildcard subdomain: http://codex.wordpress.org/Installing_WPMU#Rewriting_Rules_for_others_HTTP_Server btw they still mention blogs.php I changed it to reflect ms-sites.php and all is well.

    Now what makes me frown and ask myself if I am wasting my time here is that actually all static content that should have been handled by nginx seems to fall back to apache2 because of this rewrite. am I right?

    so basically nginx works as a front end proxy for all vhosts except this one which actually is the biggest one on the server? have I just wasted 3 days getting this to work?
     
  5. Ovidiu

    Ovidiu Active Member

    okay I finally got this baby working. quite difficult. if anyone wants any advice on setting up nginx as a friont-end proxy for apache2 ask me. I'm kind of an expert now :) lol

    now seriously, I can give you quite a few hints I had to learn the hard way...

    i.e. *.domain.tld is completely different from .domain.tld when it comes to nginx :-(

    still struggling with some smaller probs but all in all its working! seriously give me a few mroe days and I'll submit some corrections to that tutorial!
     
  6. renders

    renders New Member

    Your postings are very timely. I have installed the nginx proxy as per the howto and made some of your tweaks.

    I am now running Nginx proxy in front of several virtual servers with a significant improvement in speed.

    If you find time to update your posting or the how to, I would love to read it.

    Thanks

    Rob
     
  7. Ovidiu

    Ovidiu Active Member

    I am yet to see any improvements... and still sttruggling with a few problems. can I reach you somehow by email or irc or chat?
    Would love to discuss some problems I face...
     
  8. renders

    renders New Member

    Further Progress..

    As previously discussed, the catchall function of this howto needs work..

    I came across another howto that provides a more robust method for the nginx conf files.. This one includes failover for all virtual hosts to the apache server, ie it will keep working even if there is no viritual host created in nginx.
    http://code.google.com/p/scriptz/wiki/NginxAndApache

    I don't have a lot of virtual hosts to worry about.. I have implemented these suggested conf files on my server and it is working quite nice. I will continue to tweak and report back..

    Regards, :)
    Rob
     
  9. renders

    renders New Member

    Thought that I would share my conf files in case someone finds this helpful.

    ** I am continuing to tweak and as such, some of these settings may not be appropriate for everyone. **

    nginx.conf

    Code:
    user www-data;
    worker_processes  1;
    
    error_log  /var/log/nginx/error.log;
    pid        /var/run/nginx.pid;
    
    events {
        worker_connections  2048;
        use epoll;
    }
    
    http {
        
        root  /var/www/;
        error_page   502 503 504  /50x.html;
        
        server_names_hash_max_size 512;
        server_names_hash_bucket_size 128;
        
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;
        
    
        
        client_header_timeout   10m;
        client_body_timeout     10m;
        send_timeout            10m;
        connection_pool_size           512;
        client_header_buffer_size       1k;
        large_client_header_buffers     4 2k;
        request_pool_size               4k;
        client_body_temp_path /var/lib/nginx/body 1 2;  
        
        gzip  on;
        gzip_http_version 1.0;
        gzip_min_length  5000;
        gzip_types text/plain text/css image/x-icon application/x-javascript application/javascript text/javascript application/atom+xml application/xml;
        gzip_buffers 4 8k;    
        gzip_vary         on;
        gzip_disable "MSIE [1-6]\.(?!.*SV1)";
        gzip_proxied  any;
        gzip_comp_level 2;
    
        output_buffers  1 32k;
        postpone_output 1460;
        sendfile        on;
        #tcp_nopush     on;
        keepalive_timeout       75 20;
        tcp_nodelay        on;
        ignore_invalid_headers  on;
        index index.html;
        
        server_tokens off;
    
        access_log	  /var/log/nginx/access.log;
        error_log     /var/log/nginx/error_log;
    
        #default nginx virtual host server
        #it's used if there is no other matching nginx virtual host found
        server {      
    	listen 80;      
    	#you can access nginx internal stats using lynx or alike console based web browser or munin-node    
    	#at http://127.0.0.1/nginx_status address
    	location /nginx_status {
    	    stub_status on;
    	    access_log   off;
    	    allow 127.0.0.1;
    	    deny all;
    	}
    	
            #default proxy settings for each virtual host
            include /etc/nginx/proxy.conf;
        }
        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
    }
    
    
    proxy.conf

    Code:
    location / {
       proxy_pass         http://127.0.0.1:82/;
       proxy_redirect     default;
       proxy_set_header   Host             $host;
       proxy_set_header   X-Real-IP        $remote_addr;
       proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
       client_max_body_size       64m;
       client_body_buffer_size    128k;
       proxy_connect_timeout      90;
       proxy_send_timeout         90;
       proxy_read_timeout         90;
       proxy_buffer_size          4k;
       proxy_buffers              4 32k;
       proxy_busy_buffers_size    64k;
       proxy_temp_file_write_size 64k;
    }
    
    proxy_fallback.conf

    Code:
    #proxy options can't be set inside if directive 
    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
     if (!-f $request_filename) {
     break;
     proxy_pass http://127.0.0.1:82;
    }
    
    Virtual conf file, each virtual host needs one of these otherwise nginx just passes the entire request thru to Apache.

    Code:
    server {
       listen 80;
       server_name VIRTUAL1.com www.VIRTUAL1.com;
       #default proxy settings shared are among all virtual hosts
       include /etc/nginx/proxy.conf;
          location ~* ^.+.(jpe?g|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|html?|txt|tar|mid|midi|wav|bmp|rtf|js|swf|avi|mp3)$ {
               #forcing browser to cache locally static content for 1 day, set this longer as needed.
               expires 1d;
               root /var/www/VIRTUAL1.com/web/;
               access_log  /var/log/ispconfig/httpd/VIRTUAL1.com/access.log;
            
               #graceful fallback in case if static content doesn't exist
               include /etc/nginx/proxy_fallback.conf;
          }
    }
    
     
    Last edited: Nov 18, 2010
  10. renders

    renders New Member

    Couple of adjustments made based on further nginx forum recommendations.

    1. Increased the worker processes to 2 and reduced worker connections to 1024. The use of this option is based on number of cpu's available and the need to reduce disk i/o.

    2. Added Index index.php index.html index.htm to the http group. This option is global and is passed on. No need to include this elsewhere.

    The system went live yesterday with 7 sites functioning. Immediate improvement over the previous system was noticed. The images are all loading extremely fast and the server load is very low, typically .15.

    As mentioned before, this installation is based on the Nginx Catchall for Ispconfig 3. I have removed the kludgy www redirect since it did not work very well. The new failover feature improves the functionality. I had forgotten to create an nginx virtual host conf file for one of my sites and noticed the impact on the apache connections. After creating the vhost conf, apache dropped to half the connections..

    One last word, READ the WIKI. The nginx site has a pretty good wiki describing many of the features uses for this proxy.

    Hope you find this info helpful.

    Rob
     
  11. maced0n

    maced0n New Member

  12. maced0n

    maced0n New Member

    If anyone else have a same problem this is because my nginx was 0.6, it should be > 0.7.
     
  13. demon326

    demon326 New Member

    Sorry to bump this topic,

    But i don't want to open a new one for the same issue... I got it "working" thanks to this tutorial: http://tumblr.intranation.com/post/766288369/using-nginx-reverse-proxy

    instead of port 8080 i used 82, so both systems ar running pretty fine, but i can't get the sites display to show, it just says
    So i assume that all the content is getting forwarded to apache instead of Nginx, although httpfox says the server is now Nginx

    (Status-Rule) HTTP/1.1 304 Not Modified
    Server nginx
    Date Wed, 09 Feb 2011 05:21:24 GMT
    Connection keep-alive
    Keep-Alive timeout=20
    Etag "20a0d-b1-49bc577241db8"
    Vary Accept-Encoding
     
    Last edited: Feb 9, 2011
  14. iain17

    iain17 New Member

    Where would you guys place this line of code?: ab -c 100 -n 10000 http://hostname/index.php


    Thanks, Someone posted it on a tutorial and I'm trying to figure out where for starters he found it and where he put it.
    He's saying it gives amazing results, would love to hear from someone where I could place it in my configuration. Cuz atm it's working as intended, all my websites are functional with ispconfig etc and the headers are telling me the website is provided by Nginx so that's all happy and good.

    But would really appreciate it if someone could tell me where to put that line of code, or even if it's that necessary
     
  15. iain17

    iain17 New Member

    I also found that there is one flaw in this whole idea, and that is when things like roundcube squirrelmail or even phpmyadmin are hosted outside of /var/www/* things like css etc that are managed by Nginx result in a 404 error.

    Thus resulting improper function of these services, could someone help me find a fix cuz I can't find one.
     
  16. falko

    falko Super Moderator Howtoforge Staff

    It's a command (it does a benchmark if you are interested to see how fast the server is), so you type it on the command line.
     

Share This Page