Welcome! Log In Create A New Profile

Advanced

location match help

Posted by sujithpaily 
location match help
July 15, 2013 11:41AM
Hello

I am new to nginx. Please help me to set up following configuration
The root folder for site.com is /var/www(root /var/www)
But when somebody open http://site.com I want to load contents from /var/www/home
If somebody try http://site.com/anything I want to load contents from /var/www/anything

I tried following

root /var/www;
location = / {
root /var/www/home
}

didn't work

Also tried

location = / {
root /var/www/home
}

location / {
root /var/www
}

didn't work


Please help
Re: location match help
July 18, 2013 07:45PM
I presume you're refering to all _files_ should be served from the /home directory if the user visits / ?

For example:
http://example.com/file.html -> /var/www/home/file.html
http://example.com/ -> /var/www/home/
http://example.com/home/file.html -> /var/www/home/file.html
http://example.com/css/style.css -> /var/www/css/style.css
http://example.com/css/ -> /var/www/css/
http://example.com/a/b/c.html -> /var/www/a/b/c.html

If this is the case, perhaps this could work:

root /var/www;
rewrite ^/([^/]*)$ /home/$1 break;

(untested)
Re: location match help
July 19, 2013 07:49AM
Hello Yumi

Thanks for the update. My current set up is
root /var/www

location = / {
root /var/www/home

}



M requrirement is
site.com /var/www/home
site.com/blog /var/www/blog
site.com/user /var/www/user
site.com/anything /var/www/anything

That is when I try site.com it should load from /var/www/home everything else should read from /var/www

It works with following configuration

root /var/www;
location = / {
rewrite ^ /home break;
}

But issue is site.com will redirect to site.com/home

This redirection can avoid by adding a '/' after home

root /var/www
location = / {
rewrite ^ /home/ break;
}

With above setup when I try site.com it will load index.html from /var/www/home as needed. But it is not reading css,js folders from same location it is trying load those folders from /var/www
Re: location match help
July 20, 2013 04:28AM
Do you want *specific* folders to be served from the /home directory instead of the root?
If so, you'll need to come up with a list of which folders you want served from /home, or a list of folders you want served from /

Or do you wish to try serving from /home, then falling back to /?
If so, you can try the try_files directive: http://wiki.nginx.org/HttpCoreModule#try_files
Re: location match help
July 20, 2013 09:12AM
This is my directory structure
/var/www/home/index.html
/var/www/home/css/My.css
/vaw/www/blog/index.html
/var/www/admin/index.html



I want
http://site.com -> /var/www/home/index.html(index.html read css/my.css also)
http://site.com/blog--> /var/www/blog/indexhtml
http://site.com/admin-> /var/www/admin/index.html
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 64
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready