I have a web app which can be accessed from http://example.com
I'm developing locally another web app which I want to access it from the same domain but different path. Let's say I want all traffic from http://example.com/my-local-app/*
go to my web app served from localhost:8080
. All other requests should go to remote http://example.com
. How can I achieve that?
2 Answers
You can consider nginx Reverse Proxy.
Example :
location ~ /my-local-app {
proxy_pass http://localhost:8080/;
}
In this situation, if any request comes to /my-local-app nginx will forward internally to localhost and return the response as well.
-
The problem is that I want to direct part of traffic to from one domain to localhost and another part to remote host.– latataNov 14, 2018 at 8:53
-
You can use virtualhosts
for your two applications. One application will be accessible from http://first.example.com
and another will be using http://second.example.com
. You cannot run one web server on two different ports. Another option is to use nginx
as you are using now and install apache
on the same machine but configure apache
server to run on a different port (8080) whereas nginx
is running on port 80. Although not recommended, this would mean you need to manage two different web servers instead of one.
virtualhosts
is the way IMO.
-
I need to serve both apps from the exact same domain, only paths define the final destination of request.– latataNov 13, 2018 at 22:43