HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Installation/Configuration (http://www.howtoforge.com/forums/forumdisplay.php?f=27)
-   -   Nginx for static and $host (http://www.howtoforge.com/forums/showthread.php?t=53700)

GarGamel55 7th August 2011 20:33

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 :()

falko 8th August 2011 10:28

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;
}


GarGamel55 25th August 2011 15:41

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ą ! :D


All times are GMT +2. The time now is 17:03.

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