V
V
Vitaly2020-10-29 04:45:49
Nginx
Vitaly, 2020-10-29 04:45:49

How to set up a proxy webserver and bind subdomains for services running in a virtual machine?

Confused about the configuration.
There is a host on which bind, apache and KVM virtual machines.
The virtual machine runs several services both on ports 80/443 and on non-standard ones.
There is a main domain (domain.ru), and services to which you also need to add subdomains (service1.domain.ru, service2.domain.ru).

As I did now:
On the host, in each zone, bind added the required number of A-records like

domain.ru.  IN      A       XX.XX.XX.XX
service1 IN      A       XX.XX.XX.XX
service2 IN      A       XX.XX.XX.XX


In the Apache virtual host config:
<VirtualHost *:80>
    ServerName domain.ru
    ServerAlias service1.domain.ru service2.domain.ru
    ServerAdmin [email protected]
    DocumentRoot /var/www/html/

    ProxyRequests Off
    ProxyPass / http://192.168.202.2
    ProxyPassReverse / http://192.168.202.2

    <Location />
        Require all granted
    </Location>

    ErrorLog ${APACHE_LOG_DIR}/domain.ru_error.log
    CustomLog ${APACHE_LOG_DIR}/domain.ru_access.log combined
    LogLevel error
</VirtualHost>


Am I correct in specifying all used subdomains in ServerAlias, or is it better somehow differently?
192.168.202.2 is the ip of the virtual machine.
There, in turn, nginx accepts requests and proxies for services.
domain.ru works correctly. The config is like this:
server {
        listen 80;
        listen [::]:80;

        server_name domain.ru www.domain.ru 192.168.202.2;
        root /srv/www/domain.ru/html;

        access_log /srv/www/domain.ru/logs/domain.ru.access;
        error_log /srv/www/domain.ru/logs/domain.ru.error error;

        index index.html index.htm;

        location / {
                try_files $uri $uri/ =404;
        }
}

And service1 does not work, the browser shows the contents of /srv/www/domain.ru/html instead of /srv/service1/build
server {
   listen 80;
   listen [::]:80;
   root /srv/service1/build;
   server_name service1.domain.ru;
   index index.html index.htm;
   location / {
   }
}

I don't need port 80 at all. If you add an SSL certificate, is it better to configure it on a host with apache, or on a virtual machine with nginx?
And if, for example, I have an API running on port 50000, for example, how can I bind a subdomain to it so that the API is available at service3.domain.ru:50000?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question