question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how to configure multiple domain (virtual host) and multiple virtual port

See original GitHub issue

I have run your image with command below.

docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro \
    --name my-nginx-proxy --network=mynetwork jwilder/nginx-proxy

my software run in single container and listen on port 81,82

  • port 81 designed for domain a.mydomain
  • port 82 designed for domain b.mydomain

case 1, I have use these command. It’s work.

docker run -d --network=mynetwork -e VIRTUAL_PORT=81 -e VIRTUAL_HOST=a.mydomain myimage

case 2, I have use these command. It’s work.

docker run -d --network=mynetwork -e VIRTUAL_PORT=82 -e VIRTUAL_HOST=b.mydomain myimage

Question, how to configure for the following situation?

I would like to use port 81 with domain a.mydomain and port 82 with domain b.mydomain in single container.

I have tried with the following command. It 's not work. docker run -d --network=mynetwork -e VIRTUAL_PORT=81,82 -e VIRTUAL_HOST=a.mydomain,b.mydomain myimage

Please help. Thanks you.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:7
  • Comments:5

github_iconTop GitHub Comments

10reactions
tkw1536commented, Jul 1, 2020

@jakata007 @first087: Here is a workaround until a new feature is implemented.

# start the nginx proxy
docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro \
    --name my-nginx-proxy --network=mynetwork jwilder/nginx-proxy

# start the application container, take note that:
# - it is named (so that the proxies below can see it)
# - it does not have anything exposed
docker run -d --network=mynetwork --name myapp application-with-two-ports

# For each port that you want to expose, configure a pseudo container. 
# These only forward to the 'myapp' container above.
# They are additionally labeled for 'nginx-proxy' to pick up on. 
docker run -d --network=mynetwork -e VIRTUAL_PORT=80 -e VIRTUAL_HOST=a.mydomain \
    -e REMOTE_HOST=myapp -e REMOTE_PORT=81 marcnuri/port-forward
docker run -d --network=mynetwork -e VIRTUAL_PORT=80 -e VIRTUAL_HOST=b.mydomain \
    -e REMOTE_HOST=myapp -e REMOTE_PORT=82 marcnuri/port-forward

Disclaimer: The image for proxying isn’t mine, I haven’t tested this. If for some reason you don’t trust random images, you can always build it from the Dockerfile or make your own image. It should contain something like:

CMD socat tcp-listen:$LOCAL_PORT,reuseaddr,fork tcp:$REMOTE_HOST:$REMOTE_PORT

Also, I doubt @jwilder is currently developing new features, see https://github.com/nginx-proxy/nginx-proxy/issues/1304#issuecomment-535290685. So someone would have to make a PR and hope it gets merged.

2reactions
zahaimcommented, Aug 31, 2020

Many thanks for that workaround @tkw1536 , I was about to setup another registry / nexus just for 1 customer to achieve this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Host Multiple Websites with Apache Virtual Hosts
Apache's virtual hosts can run multiple websites on a single server. ... Line 4: Add www to your domain name for ServerAlias.
Read more >
How To Set Up Apache Virtual Hosts on Ubuntu 18.04
This tutorial will guide you through setting up multiple domains and websites using Apache virtual hosts on an Ubuntu 18.04 server.
Read more >
How to Configure Multiple Sites with Apache - Liquid Web
Step 1: Make a Directory for Each Site · Step 2: Set Folder Permissions · Step 3: Set up an Index Page ·...
Read more >
VirtualHost Examples - Apache HTTP Server Version 2.4
Running different sites on different ports. ... You have multiple domains going to the same IP and also want to serve multiple ports....
Read more >
Serve multiple domains by using virtual hosts - - Rackspace
First you create a folder in your public_html folder with the relevant files for the blog (for example, a WordPress installation). Then you ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found