@springboot777

Почему nginx не перенаправляет с 80 порта на 8081?

У меня есть приложение spring boot которое работает на порту 8081
В nginx удален default конфиг
И настроен прокси с 80 порта на порт 8081 вот конфиг
server {
        listen 80;
        listen [::]:80;

        # Add index.php to the list if you are using PHP

        access_log  /var/log/nginx/mushroomer.access.log;
        error_log /var/log/nginx/mushroomer.error.log;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                proxy_set_header X-Real-IP  $remote_addr;
                proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass http://127.0.0.1:8081;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}

Но при заходе на 127.0.0.1 открывается страница с приветствием nginx
Почему не работает прокси конфиг?
  • Вопрос задан
  • 125 просмотров
Пригласить эксперта
Ответы на вопрос 2
wapster92
@wapster92
upstream serve {
  server 0.0.0.0:8081;
  keepalive 15;
}

server {
        listen 80;
        listen [::]:80;

        # Add index.php to the list if you are using PHP

        access_log  /var/log/nginx/mushroomer.access.log;
        error_log /var/log/nginx/mushroomer.error.log;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                proxy_set_header X-Real-IP  $remote_addr;
                proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass http://serve;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}
Ответ написан
@springboot777 Автор вопроса
upstream serve {
  server 127.0.0.1:8081;
  keepalive 15;
}

server {
        listen 80;
        listen [::]:80;
    server_name 127.0.0.1;
        # Add index.php to the list if you are using PHP

        access_log  /var/log/nginx/mushroomer.access.log;
        error_log /var/log/nginx/mushroomer.error.log;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                proxy_set_header X-Real-IP  $remote_addr;
                proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass http://serve;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}

Нехватало server_name 127.0.0.1
Ответ написан
Комментировать
Ваш ответ на вопрос

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

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