Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > HOWTO-Related Questions

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #21  
Old 3rd November 2010, 19:18
Ovidiu Ovidiu is offline
Senior Member
 
Join Date: Sep 2005
Posts: 1,266
Thanks: 82
Thanked 24 Times in 20 Posts
Default

deleted, accidental double post :-(

Last edited by Ovidiu; 3rd November 2010 at 19:23. Reason: double post
Reply With Quote
Sponsored Links
  #22  
Old 3rd November 2010, 19:21
Ovidiu Ovidiu is offline
Senior Member
 
Join Date: Sep 2005
Posts: 1,266
Thanks: 82
Thanked 24 Times in 20 Posts
Default

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:

Quote:
2010/11/03 19:17:28 [error] 32439#0: *3 open() "/var/www/adi.zice.ro/web/wp-includes/images/adminbar.png" failed (2: No such file or directory), client: 196.210.184.232, server: _, request: "GET /wp-includes/images/adminbar.png HTTP/1.1", host: "adi.zice.ro:82", referrer: "http://adi.zice.ro:82/"
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:
Quote:
set $site_dir $host; if ($host ~ ^www\.(.*)) { set $site_dir $1; } root /var/www/$site_dir/web;
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:
Quote:
rewrite ^.*/files/(.*) /wp-content/blogs.php?file=$1;
if (!-e $request_filename) {
rewrite ^.+?(/wp-.*) $1 last;
rewrite ^.+?(/.*\.php)$ $1 last;
rewrite ^ /index.php last;
}
any help out there?
Reply With Quote
  #23  
Old 3rd November 2010, 19:56
Ovidiu Ovidiu is offline
Senior Member
 
Join Date: Sep 2005
Posts: 1,266
Thanks: 82
Thanked 24 Times in 20 Posts
Default

something along the lines of:
Quote:
if ($host stripped of www and any subdomains)==zice.ro {rewrite ^.*/files/(.*) /wp-content/blogs.php?file=$1;
if (!-e $request_filename) {
rewrite ^.+?(/wp-.*) $1 last;
rewrite ^.+?(/.*\.php)$ $1 last;
rewrite ^ /index.php last;
} }
:-)
Reply With Quote
  #24  
Old 4th November 2010, 19:55
Ovidiu Ovidiu is offline
Senior Member
 
Join Date: Sep 2005
Posts: 1,266
Thanks: 82
Thanked 24 Times in 20 Posts
Default

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/Installin...rs_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?
Reply With Quote
  #25  
Old 5th November 2010, 02:25
Ovidiu Ovidiu is offline
Senior Member
 
Join Date: Sep 2005
Posts: 1,266
Thanks: 82
Thanked 24 Times in 20 Posts
Default

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!
Reply With Quote
  #26  
Old 7th November 2010, 04:38
renders renders is offline
Junior Member
 
Join Date: Jan 2008
Location: Ontario Canada
Posts: 25
Thanks: 1
Thanked 6 Times in 4 Posts
Thumbs up

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
Reply With Quote
  #27  
Old 9th November 2010, 16:49
Ovidiu Ovidiu is offline
Senior Member
 
Join Date: Sep 2005
Posts: 1,266
Thanks: 82
Thanked 24 Times in 20 Posts
Default

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...
Reply With Quote
  #28  
Old 18th November 2010, 18:06
renders renders is offline
Junior Member
 
Join Date: Jan 2008
Location: Ontario Canada
Posts: 25
Thanks: 1
Thanked 6 Times in 4 Posts
Smile 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
Reply With Quote
  #29  
Old 18th November 2010, 19:30
renders renders is offline
Junior Member
 
Join Date: Jan 2008
Location: Ontario Canada
Posts: 25
Thanks: 1
Thanked 6 Times in 4 Posts
Smile

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 by renders; 18th November 2010 at 19:33. Reason: typos
Reply With Quote
The Following User Says Thank You to renders For This Useful Post:
falko (19th November 2010)
  #30  
Old 23rd November 2010, 15:00
renders renders is offline
Junior Member
 
Join Date: Jan 2008
Location: Ontario Canada
Posts: 25
Thanks: 1
Thanked 6 Times in 4 Posts
 
Smile

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
Reply With Quote
Reply

Bookmarks

Tags
apache2, ispcfg3, nginx, proxy, reverse

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Nginx Catch-All Host As Front End To Apache For ISPConfig 3 On Debian Lenny fatmaddin2000 HOWTO-Related Questions 1 27th June 2010 21:52
trying to install roundcubemail ressel Installation/Configuration 13 24th December 2009 20:13
problems with suexec gobokster Installation/Configuration 7 7th May 2009 13:33
CENTOS 5 Ping Problem gAnDo Server Operation 11 28th March 2008 20:58
Problem with the installation of Dokeos (LMS) in ISPConfig jofranco General 4 28th April 2006 00:45


All times are GMT +2. The time now is 07:19.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.