U
U
ukoHka2015-05-04 08:23:16
ubuntu
ukoHka, 2015-05-04 08:23:16

How to set one IP address for two virtual servers?

On the server under OS from Microsoft, two virtual servers with Ubuntu on board are installed via Hyper-V. Each virtual server has its own internal IP address and a common external one. Apache is also installed on each of them and sites are flooded. The sites of the first server are quietly opened, and the second server only opens the site by default if you enter by IP. If you go to the domain bound to the external IP, then the default site for the first server is loaded. How can I set up one external IP address for two virtual servers so that sites load correctly?
Google says that you need to configure Apache or ports for this. About Apache it is not clear which one to configure, as I understand it, in my situation Apache should be on Windows and create servers through it. About ports, I did not understand how it would work so that the user did not type example.com: 10000, that is, the port listened through Apache was automatically substituted for sites on the second server.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergei Borisov, 2015-05-04
@ukoHka

As I understand it, you want to drive one site (or one set of sites) on one virtual machine, another site (or again, another set of sites) on another virtual machine.
In your case, someone should listen to the ip address. It can be:
1) host machine (windows), with Apache. Maybe IIS can do this, but I'm not an expert here.
2) the third virtual machine, on which only a proxy web server is installed. Apache or nginx. In this case, the other two machines for this third must be accessible by internal ip addresses, and you associate the external ip only with this third.

D
Dmitry Luponos, 2015-05-04
@Bessome

we make a machine with the nginx service, with a white IP; nginx in proxy mode. In the nginx config, we prescribe where which site is located, I give an example of my config:

[email protected]:/etc/nginx# cat nginx.conf
user www-data;
worker_processes  4;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    proxy_cache_path /var/lib/nginx/proxy levels=1:2 keys_zone=proxy_cache:64m max_size=128m inactive=3d;
    reset_timedout_connection on;
    client_header_timeout 15;
    client_body_timeout 15;
    send_timeout 5;
    keepalive_timeout        30 15;
    limit_conn_zone  $binary_remote_addr  zone=perip:5m;
    limit_conn perip 50;
    connection_pool_size 256;
    client_header_buffer_size 1k;
    large_client_header_buffers 4 2k;
    request_pool_size 4k;
    types_hash_max_size 2048;
    server_names_hash_bucket_size  64;
    access_log  /var/log/nginx/access.log;
    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay        on;
    gzip              on;
    gzip_proxied      expired no-cache no-store private auth;
    gzip_buffers      16 8k;
    gzip_comp_level   5;
    gzip_http_version 1.0;
    gzip_min_length   0;
    gzip_vary         on;
    server_tokens off;
    output_buffers 1 32k;
    postpone_output 1460;
    ignore_invalid_headers on;
    client_max_body_size 64m;
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

[email protected]:/etc/nginx/sites-enabled# cat default
server {
        listen   *:80; ## listen for ipv4; this line is default and implied
        return 301 https://$host$request_uri;
}

server {

    listen 443;
    server_name blabla.ru;

    ssl_certificate           /etc/nginx/cert.crt;
    ssl_certificate_key       /etc/nginx/cert.key;

    ssl on;
    ssl_session_cache  builtin:1000  shared:SSL:10m;
    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
    ssl_prefer_server_ciphers on;

    access_log /var/log/nginx/access.log;

        proxy_buffering on;
        limit_conn perip 32;

    location / {
        proxy_pass http://192.168.20.5/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_connect_timeout 120;
        proxy_send_timeout 120;
        proxy_read_timeout 180;
    }

    location /pve {
        proxy_pass https://192.168.20.100:8006/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_connect_timeout 120;
        proxy_send_timeout 120;
        proxy_read_timeout 180;
    }

    location /cam32 {
        proxy_pass http://10.1.1.239/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_connect_timeout 120;
        proxy_send_timeout 120;
        proxy_read_timeout 180;
    }
}

two files -
1. nginx.conf config
2. default config, located /etc/nginx/sites-enabled
in the config (2) several different subnet servers are registered, which nginx shows on various links. Works only on https, because I need secure traffic. Can be modified for http by removing the line "return 301 https://$host$request_uri; " and assigning the port not 443, but 80. You also need to remove everything related to ssl from the config.
We do not touch two machines with internal IP.

A
aroun, 2015-05-14
@aroun

Will be without ports.
In this case, the server determines by the header to which virtual host the request is assigned and sends it to this virtual host.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question