Reputation: 896
I'm building a sort of e-commerce in AngularJS.
All the stores are referenced by a unique string (mystore, store2, etc) and to see their products you have to go to: example.com/#/mystore/products or example.com/#/store2/products
What i would like to do now is to set up a nginx rewrite so that mystore can be accessed by
mystore.example.com/products
instead of
example.com/#/mystore/products
Sort of how slack is doing for his customers
Is this possible ?
I tried with this configuration
server {
listen 80;
server_name ~^(.*?).example.com;
location / {
resolver 8.8.8.8;
proxy_pass http://example.com/#/$1;
}
}
The problem now is that this applies also to the scripts files and so
mystore.example.com/scripts/main.js
now points to
example.com/#/scripts/main.js
and of course nothing is found and the app doesn't work. Is there a way to do it only for the angular param and not for everything else ?
Upvotes: 0
Views: 207
Reputation: 146630
Add additional nested route to filter such cases
server {
listen 80;
server_name ~^(.*?).example.com;
location / {
resolver 8.8.8.8;
proxy_pass http://example.com/#/$1;
location ~* ^/(scripts|static|images) {
proxy_pass http://example.com/;
}
}
}
Upvotes: 1