Created
September 21, 2023 04:07
-
-
Save axmad386/d8a93e51ff84f3f060a467e3cfdb2e56 to your computer and use it in GitHub Desktop.
Dynamic Subdomain Proxied to sub path with nginx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
server_name ~^(?<subdomain>.+)\.domain\.com domain.com; | |
# Location block for path that threated as assets | |
location ~* ^/(?<asset>image|css|js|fonts|@vite|node_modules)/(.*) { | |
proxy_pass http://127.0.0.1:3000/$asset/$2; | |
proxy_set_header Host $host; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
} | |
# Location block for assets with specific extensions | |
location ~* \.(js|ts|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|svelte)$ { | |
proxy_pass http://127.0.0.1:3000$request_uri; | |
proxy_set_header Host $host; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
} | |
location / { | |
set $subdomain_suffix ""; | |
if ($subdomain) { | |
set $subdomain_suffix "/page/$subdomain"; | |
} | |
proxy_pass http://127.0.0.1:3000$subdomain_suffix$request_uri; | |
proxy_set_header Host $host; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment