I have a domain. Let's say test.com. I have to forward requests of a route of this domain to a subdomain and render response of the same without Changing URL via Caddy Server
For Example,
Request Flow:
test.com/home -> Caddy -> https://demo.test.com/home
Response Flow:
test.com/home <- Caddy <- https://demo.test.com/home
I tried following reverse_proxy rules to achieve this but was unable to achieve the desired response.
test.com {
reverse_proxy /home https://demo.test.com/home {
#proxy to subdomain
header_up Host demo.test.com
}
}
This crashes the whole site. I think the reason for this is that Caddy doesn't support such type of Upstream Addresses. Valid addresses can be seen here.
Then, I tried the valid one -
test.com {
reverse_proxy /home https://demo.test.com {
#proxy to subdomain
header_up Host demo.test.com
}
}
This didn't led to any error but this didn't bring me any response either. The reason for this can be that I am forwarding the request from Client to another Client and not the actual server.
Hence, I tried to hit the IP address associated with the sub domain
test.com {
reverse_proxy /home <IP-address> {
#proxy to subdomain
header_up Host demo.test.com
}
}
This changes the actual route i.e. in the web-browser it changes the URL from test.com/home to demo.test.com. But it doesn't brought any response either.
Kindly comment if there is any possible solution for forwarding the request to a sub-domain route.
If the solution is not supported by Caddy but by another Web Server, that will also be helpful.
Related
I want to setup an nginx proxy for a legacy systems api. My barebone Setup for the redirect does work for redirects without ports:
# test redirecting to html
location /api {
proxy_pass https://my.host.de/main.html;
}
But some test systems do have Ports inside their HTTPS location e.g. https://my.host.de:8441/.../
# test redirecting to html
location /api {
proxy_pass https://my.host.de:8441/main.html;
}
So if I add a rule like this the nginx will log a 499 error and the Requesting Browser will endlessly loop, and the Target System wont show any logs (so no request was made).
I tried using proxy_redirect http://my.host.de:8441/ http://my.host.de/ (and the other way arouund) which didnt show any improvments. My guess is that the Port is not used? Since there is no request recorded on the target system.
Any Ideas what the problem could be?
I have a EC2 instance on which I am running a React App and a domain from Route 53, for example xyz.com.
For this xyz.com I have two subdomains say www.xyz.com and demo.xyz.com.
Now, traditionally my React App serves on PORT 3000 on this instance. I have configured the IP with the PORT using nginx on my instance, something like this 192.1.1:3000. Now whenever I hit this domain (www.xyz.com) I am redirected to 192.1.1:3000.
For example, if I have two versions of my app called dev and prod. dev serves on PORT 3000 and prod serves on PORT 3002.
I want to www.xyz.com to redirect to 3000 and demo.xyz.com redirect to 3002. Both of these are from the same DNS provider.
Is there a away to achieve this?
try this way:
server {
server_name www.xyz.com;
location / {
proxy_pass http://192.1.1:3000;
}
}
server {
server_name demo.xyz.com;
location / {
proxy_pass http://192.1.1:3002;
}
}
( add extra parameters if you want to add regarding the request, header etc )
I hope this answer helps you.
Feel free to comment if you get any errors in this and don't forget to mention the answer as accepted if it works. It'll help the others who is looking for the silimar answer.
I have a super basic question. I have a GoDaddy account set up with subdomain xxx.mydomain.com. I also have some services running in an AWS instance on xxx.xxx.xxx.xxx:7000. My question is, what do I do to configure so that when people click xxx.mydomain.com it goes to xxx.xxx.xxx.xxx:7000?
I am not talking about domain forwarding. In fact, I also hope to do the same for yyy.mydomain.com to link it to xxx.xxx.xxx.xxx:5000. I am running Ngnix in xxx.xxx.xxx.xxx. Maybe I need to configure something there?
You want a reverse proxy.
Add two A-records to your DNS configuration to map the subdomains to the IP address of the AWS instance. With GoDaddy, put xxx / yyy in the "Host" field and the IP address in the "Points to" field. (more info)
Since you already have Nginx running, you can use it as a reverse proxy for the two subdomains. Therefore, add two more server blocks to Nginx's configuration file. A very simple one could look like this:
http {
# ...
server {
server_name xxx.mydomain.com;
location / {
proxy_pass http://localhost:7000;
}
}
server {
server_name yyy.mydomain.com;
location / {
proxy_pass http://localhost:5000;
}
}
}
You might want to rewrite some headers depending on your services/applications (more info). Also, consider to use Nginx for SSL termination (more info).
I have written a Flask website which I hosted with waitress on a Ubuntu 20.04 VM server at port 5000, but now I'd like to do it more properly with uWSGI/Nginx.
To learn uWSGI/Nginx I am following this tutorial: https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uwsgi-and-nginx-on-ubuntu-20-04
Here in step 6 it tells my to configure Nginx as follows:
server {
listen 80;
server_name my_domain www.my_domain;
location / {
include uwsgi_params;
uwsgi_pass unix:/home/sammy/myproject/myproject.sock;
}
}
However if I now request the webpage for my domain, it only returns the default Nginx page.
But if I "hardcode" the public IP address of my server to the server_name:
server_name: my_domain www.my_domain MY_IP
Then it does show the correct page. I however have a feeling this is not the intended way to configure the server.
When I used the old waitress server i had told my DNS server redirect to http://MY_IP:5000/, but it is now set to redirect to http://MY_IP/. (with redirect mode 302)
So my question is, how should I set up my Domain name redirect or Nginx config so that it works without a "hardcoded" ip? Or is this something where I just need to wait the 48 hours for the DNS update to propagate?
Also an auxiliary related question, how do I make the browser url bar show the domain name instead of an IP address?
Thanks in advance!
You can go through my answer, hope it helps you as well
Regarding your question for URL name in browser, it will be there once DNS name is propagating properly and it shouldn't take more than 5-10 minutes.
Remove the IP from server name, its not supposed to be entered there.
I try to create proxy server using Nginx.
I need configure Nginx that if I request any URL address as client, Nginx must return this URL page immediately. For example I request page using param url from my server:
http://myserver.com/url=www.gogo.com
Nginx should return me page www.gogo.com
I tried in location:
proxy_pass $host
Url should contain the protocal(http/https) later on
Use IP resolver based on url belongs to your intranet or internet
For internet 8.8.8.8