Установите обратный прокси-сервер для нескольких веб-сайтов с одинаковым IP-адресом и разными портами на nginx - PullRequest
0 голосов
/ 27 мая 2020

У меня есть 2 веб-сайта, работающих на одном IP, но с разными портами.

1-й веб-сайт: xxx.yy.zz.aaa:8443 2-й веб-сайт: xxx .yy.zz.aaa: 8444

Я устанавливаю обратный прокси на nginx, но, похоже, он работает неправильно.

Есть идеи, как исправить мою конфигурацию? Мой файл conf /etc/nginx/nginx.conf

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

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

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80;
        listen       [::]:80;
        server_name  website1.com;

        # Load configuration files for the default server block.
        #include /etc/nginx/nginx.conf.default;
        #include snippets/letsencrypt.conf;

        location ^~/.well-known/acme-challenge/ {
                #allow all;
                root /usr/local/tomcat/webapps/ROOT;
        }
        location / {
                return 301 https://website1.com$request_uri;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
    server{
    listen 80;
    server_name website2.com;
    location / {
        return 301 https://website2.com$request_uri;

    }
    }
# Settings for a TLS enabled server.
#
  server {
        listen       443 ssl http2;
        listen       [::]:443 ssl http2;
        server_name  website1.com;
        root         /usr/share/nginx/html;
        ssl_certificate /etc/letsencrypt/live/website1.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/website1.com/privkey.pem;

        location / {
            if ($request_method = 'OPTIONS') {
                    add_header Access-Control-Allow-Origin $http_origin;
                    add_header Access-Control-Allow-Credentials true;
                    add_header Access-Control-Allow-Headers Content-Type,Authorization,X-Requested-With,X-HTTP-Method-Override,X-Simplicite-Authorization;
                    add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,HEAD,OPTIONS;
                    add_header Access-Control-Max-Age 1728000;
                    add_header Content-Type text/plain;
                    add_header Content-Length 0;
                    return 204;
            }
            if ($request_method = 'GET') {
                    add_header Access-Control-Allow-Origin $http_origin always;
                    add_header Access-Control-Allow-Credentials true always;
                    add_header Access-Control-Expose-Headers X-Simplicite-SessionID;
            }
            if ($request_method = 'POST') {
                    add_header Access-Control-Allow-Origin $http_origin always;
                add_header Access-Control-Allow-Credentials true always;                    add_header Access-Control-Expose-Headers X-Simplicite-SessionID;            }                   proxy_redirect off;
            proxy_buffering off;
            proxy_read_timeout 86400s;
            proxy_send_timeout 86400s;
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto https;
            proxy_pass http://localhost:8443;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
   }
}
   server{
    listen 443 ssl http2;
    server_name website2.com;
    location / {
        proxy_pass http://localhost:8444;
    }

}
}
...