-1

I am trying to achieve URL like GitHub Pages. whenever user will visit username.example.com internally it will respond from localhost:80/username

I am giving some example So that it will make the problem more understandable. what I am trying to achieve it

whenever user will visit

user1.example.com  -> localhost/user1
user2.example.com  -> localhost/user2

user1.example.com/about  -> localhost/user1/about
user2.example.com/about/somemore  -> localhost/user2/about/somemore

I hope my problem is clear to you all.

I am using nginx and I had setup wildcard for the subdomain.

Currently For any subdomain my website is showing index.html page

nitishk72
  • 101
  • 3

1 Answers1

1
server {
    server_name     ~^(?<subdomain>\w+)\.example\.com$;

    location / {
            proxy_pass https://example.com/$subdomain$request_uri ;
    }
}
flaixman
  • 211
  • 1
  • 4
  • I don't want to redirect to some other website. – nitishk72 Jan 19 '19 at 15:22
  • I have a node.js (express) webapp where I had wrote code for request url but the problem is that my code see the url parameter after the domain name. suppose you send a reuest to ```flaixman.example.com``` my code will think that you are trying to vist home page. but when you will visit ```example.com/flaixman``` then it will show your profile. – nitishk72 Jan 19 '19 at 15:26
  • Then this answer should serve you. it makes the rewrites you ask in your question. – flaixman Jan 19 '19 at 15:32
  • but I don't want that redirect should be visiable to the user browser. It should be done on my Virtual Machine only – nitishk72 Jan 19 '19 at 15:41
  • Ooooh okay, then what you want is a proxypass – flaixman Jan 19 '19 at 16:12