#1  
Old 7th August 2011, 21:33
GarGamel55 GarGamel55 is offline
Member
 
Join Date: Jul 2011
Posts: 30
Thanks: 6
Thanked 3 Times in 3 Posts
Default Nginx for static and $host

Hello,

I use Nginx Catch-All Host As Front End To Apache (for my static files) :

Code:
location ~* ^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|swf|flv|html|htm|mp3)$ {
	root   /var/www/$host/web; 
	access_log off;
	expires 30d;
I prefer that my domain name appear as www., but with the How TO, all domains starting with www will be redirected to http://domain.

In my panel, i set up my website with auto subdomain "www". So with this line "root /var/www/$host/web;" in /etc/nginx/sites-available/default it's returns a 404 error for the static files on my websites. Is normal because $host = www.mydomain.com and ispconfig is configure for mydomain.com

If i replace manualy $host by mydomain.com, it works. However, I 've several websites.

The solution would be to rename the $host variable into /etc/nginx/sites-available/default, but is that possible? Such as php $host = str_replace('.www', '', $host);

Thanks ! (again )
__________________
French webmaster
Reply With Quote
Sponsored Links
  #2  
Old 8th August 2011, 11:28
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,747 Times in 2,578 Posts
Default

You could simply create a vhost for example.com and redirect it to the www.example.com vhost:

Code:
server {
   server_name example.com;
   rewrite ^ http://www.example.com$request_uri? permanent;
}
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #3  
Old 25th August 2011, 16:41
GarGamel55 GarGamel55 is offline
Member
 
Join Date: Jul 2011
Posts: 30
Thanks: 6
Thanked 3 Times in 3 Posts
 
Default

Thanks Falko,

But this rules doesn't work for me (redirect loop error)

However, I'm inspired by your idea and I just created a virtual host like this www.domain.tld in /etc/nginx/sites-enabled/

In this file, I wrote :

Code:
server {
        server_name www.domain.tld;

        location ~* \.(jpg|jpeg|gif|css|png|js|ico|swf|mp3)$ {
        #replace $host by domain without www.
        root   /var/www/domain.tld/web;
        expires       7d;
        access_log     off;
        }

        location / {
        proxy_pass http://127.0.0.1:82;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        access_log off;
        }
}
And all is ok. Nginx catch all statics and apache php

Voilà !
__________________
French webmaster

Last edited by GarGamel55; 25th August 2011 at 16:43.
Reply With Quote
The Following User Says Thank You to GarGamel55 For This Useful Post:
falko (26th August 2011)
Reply

Bookmarks

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
question regarding the Nginx Catch-All Host As Front End To Apache For ISPConfig3 tut Ovidiu HOWTO-Related Questions 35 10th December 2012 11:59
A Working Nginx Catchall with ISPConfig 3. renders Tips/Tricks/Mods 4 15th April 2011 22:53
nginx + ISPConfig2 + subdomain sites = problem bzzik Server Operation 1 11th December 2010 16:23
Need help with Plesk, Apache, and Nginx domz Installation/Configuration 1 10th November 2008 13:03
Munin, Monit, Webalizer need help! lordshadow HOWTO-Related Questions 26 14th June 2008 22:27


All times are GMT +2. The time now is 08:09.


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