Welcome! Log In Create A New Profile

Advanced

NGINX redirection Problem - Please help me

Posted by The_Apprentice 
NGINX redirection Problem - Please help me
June 25, 2014 10:23AM
Hello everyone,

I am new to Nginx and this forum so I hope you can help me out.
I am curently developping a website made out of multiple site.
I have 3 independant wordpress sites that are all link via landing page.

The structure is as follow

User goes to www.maindomain.com and end up on a landing page.
From there, they can access 3 sites (by clicking on image). The links to the images goes to

restaurant.maindomain.com
hotel.maindomain.com
winery.maindomain.com

The roots of the sites are:
/www/webs/maindomain_com/live/main
/www/webs/maindomain_com/live/restaurant/httpdoc
/www/webs/maindomain_com/live/hotel/httpdoc
/www/webs/maindomain_com/live//winery/httpdoc

In the DNS i have set the 3 subdomain as well as the main domain.

The problem that I have is how do I create my 4 server block so that when Nginx see subdomain.maindomain.com, it uses the root directoy for that website.

Hope I explained it correctly.

Thank you all in advance

Fred



Edited 1 time(s). Last edit at 06/25/2014 10:30AM by The_Apprentice.
Re: NGINX redirection Problem - Please help me
June 25, 2014 10:58AM
http://nginx.org/en/docs/http/server_names.html

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: NGINX redirection Problem - Please help me
June 25, 2014 11:03AM
Bellow is what I came up with..

server {
listen 80;
server_name maindomain.com www.maindomain.com;

location ~ ^/\~([^/]+)/(.*)$ {
location ~ ^/\~wine/(.*)$ {
rewrite ^(.*)$ http://wine.maindomain.com$1 permanent;
}

location ~ ^/\~restaurant/(.*)$ {
rewrite ^(.*)$ http://restaurant.maindomain.com$1 permanent;
}

location ~ ^/\~hotel/(.*)$ {
rewrite ^(.*)$ http://hotel.maindomain.com$1 permanent;
}

location ~ ^/\~winery/(.*)$ {
rewrite ^(.*)$ http://winery.maindomain.com$1 permanent;
}
}

location / {
root /www/webs/maindomain_com/live/main;
try_files $uri $uri/ /index.php?$args;

location ~ \.php$ { include conf.d/php-fpm; }
}
}

Could anyone tell me if this is right?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 174
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready