I also have a same question? Anybody?
subdomain map to subdirectory route in existing Laravel project?
I have an app setup at app.example.com, and I have a forum setup at app.example.com/forum.
Is it possible using nginx to be able to create a new subdomain forum.example.com and have that map all requests to the Laravel app as if it were prefixed with the /forum route? For example, forum.example.com/view/new-post would serve the same as the app.example.com/forum/view/new-post route.
Is this possible using only nginx, or is it even possible at all?
Thanks!
For those who are looking for an answer, this is what I did solely using nginx,
in forum.example.com nginx config:
location / {
proxy_set_header Host app.example.com;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass_request_headers on;
proxy_pass_request_body on;
proxy_pass_header http;
proxy_pass http://localhost:8001/forum/;
proxy_redirect off;
}
Then the things I had to add to my app.example.com nginx config was:
server {
# for the forum.example.com proxy_pass
listen 8001 default_server;
...
}
location ~ \.php$ {
set_real_ip_from 127.0.0.1/32;
real_ip_header X-Forwarded-For;
}
location ~* \.(eot|ttf|woff|woff2)$ {
add_header Access-Control-Allow-Origin forum.example.com;
}
The set_real_ip passes the user's IP along, otherwise the IP that will get stored for them is the IP of the server
The one thing to note for sharing sessions between subdomains is you will have to set the SESSION_DOMAIN in your .env like so:
SESSION_DOMAIN=.example.com
Please or to participate in this conversation.