I have a web application where users can create their page. The web application will generate a URL like this for each page created : https://my-domain.com/page/12345. I would like to give my users the possibility to use their own domain / subdomain instead of this URL on my website by just pointing a cname record to my server.
So I ran some tests with another domain I have on Cloudflare and created the following cname record :
subdomain.domain.com. 1 IN CNAME my-web-app-domain.com.
Basically, I want subdomain.domain.com
to point to my web app domain so my users can access their page using subdomain.domain.com
.
To achieve that on my target web app server that uses nginx, I have created the following block in my nginx config file :
server {
listen 80;
server_name subdomain.domain.com;
location / {
proxy_pass http://my-web-app-domain.com/page/12345;
proxy_set_header X-Real-IP $remote_addr;
}
}
So this basically works but instead of keeping subdomain.domain.com
in the address bar, it redirects the user to http://my-web-app-domain.com/page/12345
. How can I modify my code so it keeps subdomain.domain.com
instead of redirecting?
In case it's useful, my web app uses Laravel and to test if it may be the issue, I have added this into my TrustProxies.php file but it's still the same :
protected $proxies = '*';