I want to forward requests getting to nginx like
example.com/blah
To my backend in this form:
blah.example.com/
The rewrite condition is just redirecting and I dont want the address bar to change.
if ($host ~* ^([^.]+\.[^.]+)$) {
set $host_without_subdomain $1;
rewrite ^\/(\w+)(\/.*)$ http://$1.$host_without_subdomain$2 break;
}
This is my conf:
upstream example {
server unix:/data/example/shared/tmp/pids/example.sock;
}
server {
listen 80;
server_name *.example.com;
root /data/example/current/public;
access_log /data/nginx/log/example.access.log main;
error_log /data/nginx/log/example.error.log notice;
include /etc/nginx/common/app.conf;
if ($host ~* ^([^.]+\.[^.]+)$) {
set $host_without_subdomain $1;
rewrite ^\/(\w+)(\/.*)$ http://$1.$host_without_subdomain$2 break;
}
location / {
include /etc/nginx/common/proxy.conf;
if (!-f $request_filename) {
proxy_pass http://empowerkit;
break;
}
}
location = /500.html {
root /data/example/current/public;
}
}