F
F
FaionWeb2016-06-29 15:57:55
linux
FaionWeb, 2016-06-29 15:57:55

How to setup route in debian from specific subdomain to specific port?

The bottom line is that Apache hangs on port 80, it processes www.site.com, you need to run rest api on port 7545, which should respond to the request www.api.site.com, if you just open the port, then everything is OK, i.e. . api.site.com:7545 answers about wanting to get away from the port in the address. There is no external equipment in front of the server, the link goes directly to it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Abakumov, 2016-07-01
@FaionWeb

1. on Apache you configure VirtualHost. Reconfigure Apache from 80 to any other port, such as 8080.
2. Install Nginx
3. Set up virtual hosts:
server {
listen 80;
server_name www.site.com;
access_log /var/log/nginx/www.site.com.log;
error_log /var/log/nginx/www.site.com_error.log info;
index index.php index.html index.htm;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
index index.php index.html;
}
server {
listen 80;
server_name www.api.site.com
access_log /var/log/nginx/www.api.site.com.log;
error_log /var/log/nginx/www.api.site.com_error.log info;
index index.php index.html index.htm;
location / {
proxy_pass http://127.0.0.1:7545;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
index index.php index.html;
}
4. Restart Apache and nginx and enjoy.
Pay attention, in the first virtual host you will draw requests to the www.site.com domain to the local Apache on port 8080, in the second virtual host you will draw requests to the www.api.site.com domain to a local service that listens on port 7545.
Nginx is generally very interesting thing about this. It is possible to proxy any protocol in this way.
I'll tell you from experience. I have a server park with various services scattered over the Internet and data centers. There is the cheapest VDS on which nginx is configured to proxy requests to various hosts and services, these are http, and imap, and pop3, and smtp, and https, and even ldaps. inside proxy_pass is registered on different hosts, and on those hosts a firewall is already configured to receive requests only from VDS.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question