-
-
Save keiraarts/fce947877990ac2024da05297006b6f4 to your computer and use it in GitHub Desktop.
NGIX Custom Domains
This file contains hidden or 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
#www.ashley.com -> https://viaglamour.com/ashley while displaying https://www.ashley.com URL | |
server { | |
# catch all for domains forwarded to site that don't qualify for other server blocks. | |
listen 80 default_server; | |
# get the domain name without extension to determine URL path later. | |
# regex: ^(.*?www\.)(?<domain>.+)?(.*?)(.*)\. | |
# test it on https://regex101.com/r/0GFSyj/1 | |
# sample input: https://www.ashley.com | |
# sample output: ashley | |
# group 'domain': ashley | |
server_name ~ ^(.*?www\.)(?<domain>.+)?(.*?)(.*)\.$; | |
# location responds to all requests as default | |
location / { | |
# if the original url was www.ashley.com/cart | |
# the result should render https://viaglamour.com/ashley/cart | |
# the URL bar would still show www.ashley.com/cart | |
# For my case, I need paths to have /store/ first, followed by $domain. | |
# My PHP code parses the URL path and knows which page to display etc.. | |
proxy_pass http://127.0.0.1/store/$domain/; | |
proxy_set_header Host $host; | |
proxy_set_header Referer $http_referer; | |
proxy_set_header X-Forwarded-For $remote_addr; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment