rewrite defined and wildcard subdomain with different rules
May 29, 2013 09:51AM

Got a pretty "complex" setup with rw rules and having issues to make it all work. Spent a lot of time on this and would appreciate some help.

These are the 5 rules I try to achieve. I can't combine them without something else failing. The example below have 3, 4 and 5.

1. defined domains -> http://localhost:8090/login?domain=login -> http://localhost:8090/cms?domain=cms
up to 5 more like this.

2. special case to login subdomain with appended query. -> http://localhost:8090/login/?domain=user1

3. all other subomains are user related to specific defined pages. Ex project, dashboard, resources. This is actually the same as rule 1 but its a wildcard subdomain -> http://localhost:8090/project?domain=user1 -> http://localhost:8090/dashboard?domain= user2
endles subdomains.

4 specific paths that are pass through to proxy which are for posting data. for ex /api /authenticateUser /logout -> http://localhost:8090/events

5 static files. jpg|jpeg|gif|css|png|js|ico|html (just pass to proxy) -> http://localhost:8090/css/file.css

This is what I got so far.
upstream {
server {
listen 443;
ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
server_name "~^(?<name>.*)\.domain\.com$";
rewrite_log on;

access_log /var/www/default/logs/ssl_access.log;
error_log /var/www/default/logs/ssl_error.log debug;

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;

location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
proxy_pass http://localhost:8090;
proxy_redirect off;

location /api {
proxy_pass http://localhost:8090;
proxy_redirect off;

#1 / 3
location / {
rewrite / $request_uri?domain=$name break;

proxy_pass http://localhost:8090;
proxy_redirect off;

Edited 1 time(s). Last edit at 05/29/2013 09:53AM by jonaseliasson.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 138
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