Score:0

Forward http port to another port in same machine according http header?

in flag

I'm planning make two websites in same machine. Which first website running on port 8433 and second website running on port 9433

Im using ubuntu 20.04 Assume i have two domains, let's say foo.me and bar.me Both domain is pointed to same public IP and different SSL.

consider there's an incoming request to port 80 or 443

if HTTP header contain foo.me then the request will forward to port 8433

if HTTP header contain bar.me then the request will forward to 9433.

Egidijus avatar
nz flag
What's your software stack? On linux the above can be achieved with haproxy, nginx, traefik, kong, many other proxies or traffic routers/ingress controllers with varying levels of complexity. Is your goal minimal solution? or long term management, support and monitoring quality of service?
in flag
Does this answer your question? [How can I forward requests from my web server?](https://serverfault.com/questions/1035016/how-can-i-forward-requests-from-my-web-server)
in flag
My first website is using apache-php and second website is using nodejs. Should i migrate to nginx and remove apache, i'm using linux. The link above you share to me im not sure if its work using two domain. Yes long term
Score:1
us flag

as you have two https sites you need to have two virtual hosts so no need to examine http header again. As in reply pointed by Gerald above the best is to setup it this way (for nginx):

server {
  listen 443;
  server_name foo.me;
  root /var/www/html;
  
  # SSL options left out for simplicity

  location / {
    proxy_pass http://localhost:8433/;
  }
}

server {
  listen 443;
  server_name bar.me;
  
  # SSL options left out for simplicity
  
  location / {
    proxy_pass http://localhost:9433/;
  }
}

same for port 80 - hust replace number in "listen" and don't put SSL related directives

in flag
Okay so i must delete apache and start using nginx
in flag
No, you can configure the same in Apache. See the linked question for examples.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.