I am quite new to managing http server. How should I configure nginx to achieve behaviour like this: When there is a request for example.com/foo, nginx should serve index.html from /var/www/foo directory. When there is a request for example.com/bar, nginx should serve index.html from /var/www/bar directory.
The second part of URL (foo, bar) should not be hardcoded in nginx.conf, I need something like variable.
This is part of my nginx.conf, I tried something with variable in location section but I can't get this working.
server {
listen 188.xxx.xxx.xxx;
#access_log logs/localhost.access.log main;
location ~/(\d+) {
root /var/www/$1;
index index.html index.htm;
}
}
root /var/www;
and you're done.http://188.xxx.xxx.xxx/foo
orhttp://188.xxx.xxx.xxx/bar
. How to get this working with my domain:http://example.com/foo
,http://example.com/bar
? I tried puttingserver_name example.com;
, but didn't help.