I'm trying to change displayed urls to keep all sub domain urls relative to the main domain, example maindomain.com/some_page would be served from sub.maindomain.com/some_page but to keep the displayed url in browser to maindomain.com/some_page. Considering that the main domain and the sub are hosted on different servers as explained hereunder:
maindomain.com, is wordpress powered by LEMP server with following nginx.conf:
server { listen 80; server_name maindomain.com; root /var/www/html; index index.php index.html index.htm; include /var/www/html/nginx.conf; client_max_body_size 65M; error_page 404 @sub; location / { try_files $uri $uri/ /index.php; } location /xmlrpc.php { deny all; } location = /xmlrpc.php { deny all; access_log off; log_not_found off; return 444; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.0-fpm.sock; fastcgi_intercept_errors on; } location ~* ^.+\.(?:css|cur|js|jpe?g|gif|htc|bmp|ico|rtf|png|xml|otf|ttf|eot|woff|mid|midi|woff2|svg|png|ico|zip|tgz|gz|rar|bz2)$ { expires max; log_not_found off; } # redirect all not found pages to the sub domain location @sub { rewrite ^ http://sub.maindomain.com$request_uri redirect; } }
sub.maindomain.com, is Node.js app with nginx as proxy server.
upstream app { server 127.0.0.1:9000 fail_timeout=120; } server { listen 80; server_name sub.maindomain.com; root /var/webapp; # Compression gzip on; gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css; gzip_buffers 16 8k; gzip_disable "MSIE [1-6]\."; # Error pages error_page 404 /404.html; location /404.html { root /app/public; } error_page 500 /500.html; location /500.html { root /app/public; } # Client configuration client_max_body_size 4G; keepalive_timeout 120; # Logs access_log no; # Serve static assets location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; } # Try physical files first then proxy to running application try_files $uri/index.html $uri @app; location @app { proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Url-Scheme $scheme; proxy_redirect off; rewrite ^/(.*) http://maindomain.com$1 break; proxy_pass http://app; } }
I've tried different variations of rewriting rules but nothing doing the trick.