@adrenalinruslan

Как настроить поддомены для frontend и backend?

У меня есть 2 поддомена, frontend.example.com и backend.example.com на 1 IP адресе. Как настроить nginx так, чтобы при переходе на frontend.example.com из докера доставался nuxt.

Щас, если перейти на оба поддомена, оба откроют backend приложение. Хотя frontend.example.com должен был открыть nuxt приложение.

map $sent_http_content_type $expires {
    "text/html" epoch;
    "text/html; charset=utf-8" epoch;
    default off;
}

server {
    root /var/www;
    server_tokens off;

    listen 80;

    server_name frontend.example.com;
    client_max_body_size 5M;

    gzip on;
    gzip_types text/plain application/xml text/css application/javascript;
    gzip_min_length 1000;

    location / {
        expires $expires;
        proxy_pass http://nuxt:3000;
        proxy_redirect off;
        proxy_set_header Host $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 $scheme;
    }
}

server {
    server_tokens off;

    listen 80;
    listen 443 ssl;

    server_name backend.example.com;
    client_max_body_size 5M;

    ssl_certificate /etc/letsencrypt/live/backend.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/backend.example.com/privkey.pem;

    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    if ($server_port = 80) {
        set $https_redirect 1;
    }

    if ($host ~ '^www\.') {
        set $https_redirect 1;
    }

    if ($https_redirect = 1) {
        return 301 https://backend.example.com$request_uri;
    }

    location /static/ {
        root /var/html/;
    }

    location /media/ {
        root /var/html/;
    }

    location / {
        proxy_pass http://web:8000;
        proxy_redirect off;
        proxy_set_header Host $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 $scheme;
    }

    location /cron/ {
        proxy_pass http://flower:5555;
        proxy_redirect off;
        proxy_set_header Host $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 $scheme;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_http_version 1.1;
    }

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }
}
  • Вопрос задан
  • 227 просмотров
Пригласить эксперта
Ответы на вопрос 1
Viji
@Viji
Associate DevOps Engineer
Если оба фронтэнд и бакенд работают в докере вам надо правильно пробросить порты к докер контейнерам - например сделать разные порты на localhost и пробросить к ним соответствующие порты от контейеров, еще можно установить контейнер маршрутизатор/load balancer типа того же nginx или лучше HAProxy, кот будет например между неск фронтэнд балансировать
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы