NGINX how to redirect all traffic from a port to a folder - nginx-config

I have experience with other web servers, but I am migrating to Nginx and I run into this problem.
On a computer I have several domains hosted (domain1.com.ar, domain2.net, domain3.xyz). I need all traffic to a certain port to go to a certain folder, that is, everything that goes to domain1.com.ar:1234 or domain2.net:1234 or domain3.xyz:1234 is redirected to the / www / folder foldercommun.
the query is:
How do I do it? Is it necessary to modify the configuration of each website one by one or can I do it at the server level?
Thanks in advance for helping me in this new world.

Would this be enough?
server {
listen 1234;
server_name *.domain1.com.ar *.domain2.net *.domain3.xyz;
location / {
root /www/folder/foldercommun;
}
}
If not, please tell in the comments section.

Related

How to tunnel or serve multiple ports Via Cloudflare Agrotunnel?

I had two different webapps running on port 8081 & 8082 below
http://localhost:8081 --> app1
http://localhost:8082 --> app2
I want app1 and app2 to run on single Cloudflare free temporary domain.
I had searched this and i found it can be done using a config file, please explain me from A to Z
Please explain or fix my issue, cause I'm new in this arena.
I know it's quite late to answer but I hope someone else will find this helpful.
Considering you are on a Linux machine(or any platform for that matter), go to https://one.dash.cloudflare.com and then under Access-> Tunnels.
There create a new tunnel and on selecting the right platform, run the given command on the target server. This will start a Cloudflare service that creates a tunnel to Cloudflare.
Next, under public hostname, [considering you have added your domain to cloudflare] enter a subdomain and select your domain. You can also enter the path for that subdomain.
For service type, you can select from the dropdown[http in your case] and provide with ** localhost:8081** in your case for the URL.
Submit the form and Try it out to see it it Worked.

What kind of redirection Type is dyndns using?

So i'm curious what kind of redirection dyndns.org ist using.
We used to have an Account there but we cancelled it, we build a Inhouse IP collection solution.
BUT:
Some host urls XY.dyndns.org where used for VPN (unifi l2tp) connections and i can't figure out how i have to setupt the php or .htaccess for redirecting like dyndns.org urls. dyndns was host with ip setting
what i have:
danymic IP
some Domain vpn.domain.com which gets my external IP from Modem at home (domainserver is in some Datacenter)
solution must be done with JS, PHP or .htaccess
what i want is:
vpn.domain.com is used as VPN Target Server Domain
This Domain should redirect to my external IP from Home which is the real VPN Access Point. When i use the IP directly the VPN tunnel is created properly.
i already tried with php header location and .htaccess
RewriteEngine on
RewriteRule (.*) http://10.125.111.111/$1 [R=301,L]
so i'm out of knowledge, please bring me in right direction.
what i
Tanks
As far as I could research, I would need some root server with the ability to change the IP Routing Tables. My 0815 Webserver isn't the right the choice for this.

Wrong website being shown when I pointed my domain to website in ISPConfig3

I am not really skilled in Server Administration so forgive me if I do not know how to call or term server stuff properly but I will try to explain it as much as I can.
So I have a domain name called domain.com which has two versions. Both versions of the website are hosted on different servers. The other domain I am concerned about is the one in ISPConfig 3. Let's call the one hosted in ISPConfig 3, Version2.
Right now, domain.com points to Version1. So what I do to access Version2 is use my hosts file to point the IP Address of my server to domain.com. However, the website that loads when I did the said step is that domain.com points to a different website in ISPConfig. I have 3 websites in ISPConfig 3 and the one that loads is the one I have created the most recent.
What could be the issue here? Please educate me about this server stuff. Advanced thanks!
Edit : My server is Apache by the way.
It happened to me as well.
My case: I had been using my domain, let's call it abc.com with ISPConfig 3.1 without any issues. I registered a new domain name xyz.com and pointed it to my server running ISPConfig 3. After the successful DNS propagation when I visited xyz.com it showed the contents of abc.com.
Solution:
This issue drove me insane until I found that I misspelled the domain name in my site list in ISPConfig. I deleted this site and created a new one with the correct spelling and voila it got fixed.
What's happening here?
When you type xyz.com in your browser it goes to the DNS server and requests for translation. The translated IP is actually the IP of your server. Your server looks for virtual hosts and looks for xyz.com entry. When it fails to find the vhost entry for xyz.com it automatically shows the content of abc.com [That's my understanding of it, please correct me if I'm wrong or missed anything]
I had my domains also pointing to the wrong server although mine started because I pointed the DNS zone wrongly. There are few checks you could do but take note, the lesser you go into messing with Apache hosts files the better for you. From my observation:
To start with, do ensure you are running similar versions of ISP config on all servers, so try upgrading all servers
While creating your DNS zone (zone for domain.com), if you have multiple DNS servers (all functioning) just select the main one, the section "IP" is the crucial part; if domain.com is supposed to point to ServerA, then select ServerA IP. Also remember you need to give some few minutes for changes to take effect
Run update and upgrade on all your servers (very important) and finally you can follow up with DNS tools like mxtoolbox(mxtoolbox.com) for more details.
Hope it helps

Redirect/rewrite to different internal IIS sites using query string

EDIT: Ugh I forgot to put this on Server Fault...
I have an Azure VM that is hosting a web application.
The application will be accessible via the VM's IP address:
http://191.238.112.62
I want to be able to use query strings to redirect to completely different sites that are within the local IIS. For example:
http://191.238.112.62/?site=1
would redirect to
www.site1.com
The way I have structured IIS can be seen below:
Each site has an entry in the systems host file.
127.0.0.1 wwww.site1.com
127.0.0.1 wwww.site2.com
127.0.0.1 wwww.site3.com
There is likely a better way to achieve what I am going for here so any pointers would be greatly appreciated.
Thanks.
Here is how I would do it. Not sure why you want to use query strings for this as IIS is made to do that if you configure it properly.
In your DNS server register all your websites to point to that IP. This is for when you go live. For development the hosts file is a good solution.
When you create the websites add a Host header like below
Now try loading any website by their full name
http://www.site1.com
http://www.site2.com
http://www.site3.com
Here is more info about IIS host headers.
Again, when you go live make sure you have the DNS set up for all the websites to point to the IP address of your server.
Hope this helps.
Edit based on comment:
Right, here is how I solved this in the past.
You can do all this with the hosts file but it's less painful if you have a proper DNS server to resolve the names.
The basic idea is to use slightly different URLs for development on the local machine.
All devs would have site1.com point to the IP of the shared server and site1.com.local point to 127.0.0.1. So a hosts file on a developer machine would look something like:
191.238.112.62 www.site1.com
127.0.0.1 www.site1.com.local
On all development machines you need to make sure you have the .local host header for all sites.
On the shared server you just need to add the right host headers and no hosts file changes. It's actually a bad idea to change the server hosts file.

can the different hosts (not ip) forwarding to the same port externally?

Im just wondering, can 2 or more different external hostname/DNS redirect to multiple local servers but same port?
Let's see, I have 2 DNS internet domain for an example, myserver1.com and myserver2.com, and both I have same A record to my forwarded server IP (e.g: 102.123.123.123). Under my server which only has 102.123.123.123 IP address has 2 application servers but instead of trying to make they work, I use different port for each server applications for an example, serverApp1 listening to 0.0.0.0:2010, serverApp2 listening to 0.0.0.0:2020
My point is, is there any way or how to forward my myserver1.com:2000 to serverApp1 (port 2010), and myserver2.com:2000 to serverApp2 (port 2020) but both myserver1.com and myserver2.com has a same A record?
Im quite sure either it is in iptables or /etc/hosts or BIND issues, but guide me if I missed something. And by the way, the servers and DNS records are accessible from the internet which is the firewalls are configured properly. Thanks.
I don't have much experience in that, but I think you will need a third server/firewall/proxy listening for the incoming host and route it accordingly.
Again, I don't have much experience in that, so I'm not sure if the firewall is able to do that.
I think you can use redirection servers like apache.
In my application we want to access lot of intranet servers from internet. So what we did, we configured a apache with all the mappings in httpd.
So when ever a request to apache comes, it will be redirected appropriately.
For example - I have two servers or hostname in intranet : 1) abc.com:7300/context1
2) xyz.com:8900/context2
We configured a apache with host name abcxyz.com:9000. When a request like
abcxyz.com:9000/context1 comes it will be redirected to abc.com:7300/context1 and when a request like abcxyz.com:9000/context2 comes it will be redirected to xyz.com:8900/context2.
In your case since the requests are going through the single server (102.123.123.123), you can use redirection.
Hope it helps.