Anna_Repina
@Anna_Repina
Хочу все знать

Как перенаправить nginx:master 80 порт на другой, если данный порт используется на другом сервере?

Всем привет!
На одной из машин установлен сервис+nginx, который использует порты 30443+80.
На новой ВМ в той же сети устанавливаем Gitlab+nginx с портами 50443+34080
В конфигах /etc/nginx/sites-enabled/defaul изменили 80 порт на 34080
spoiler
server {
        listen 34080 default_server;
        listen [::]:34080 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # pass PHP scripts to FastCGI server
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
        #       fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        #}

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

в основном конфиге gitlab в той же директории прописали:
spoiler
server {
  listen 34080;
  server_name gitlab.company.ltd;
}

в etc/nginx/conf.d/gitlab прописали так же
spoiler
GNU nano 6.2                                                                                                gitlab_company_ltd.conf
server {
listen 34080;
server_name gitlab.company.ltd;
access_log /var/log/nginx/gitlab.access.log;
root /var/www/gitlab/public_html/;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
}


Но nginx ругается
#systemctl status nginx
× nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2023-06-23 12:47:20 MSK; 18min ago
Docs: man:nginx(8)
Process: 1017 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
CPU: 7ms

Jun 23 12:47:20 gitlab systemd[1]: Starting A high performance web server and a reverse proxy server...
Jun 23 12:47:20 gitlab nginx[1017]: nginx: [warn] conflicting server name "gitlab.company.ltd" on 0.0.0.0:34080, ignored
Jun 23 12:47:20 gitlab nginx[1017]: nginx: [emerg] socket() [::]:34080 failed (97: Unknown error)
Jun 23 12:47:20 gitlab nginx[1017]: nginx: configuration file /etc/nginx/nginx.conf test failed
Jun 23 12:47:20 gitlab systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Jun 23 12:47:20 gitlab systemd[1]: nginx.service: Failed with result 'exit-code'.
Jun 23 12:47:20 gitlab systemd[1]: Failed to start A high performance web server and a reverse proxy server.

netstat выдает, что
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 709/nginx: master p
tcp 0 0 0.0.0.0:8060 0.0.0.0:* LISTEN 709/nginx: master p


Где еще нужно что-то исправить что бы nginx: master слушал 34080
  • Вопрос задан
  • 429 просмотров
Пригласить эксперта
Ответы на вопрос 3
@AUser0
Чем больше знаю, тем лучше понимаю, как мало знаю.
У вас в
в основном конфиге gitlab
и в /etc/nginx/conf.d/gitlab прописан один и тот же server_name gitlab.company.ltd;. Удалите один из server { ... } - конфликт пропадёт, очевидно же!

P.S. И уберите listen [::]:34080 default_server;, именно это не даёт стартовать nginx-у.
Ответ написан
Комментировать
@Zerg89
nginx -T введи и посмотри что не так
Ответ написан
martin74ua
@martin74ua Куратор тега Linux
Linux administrator
conflicting server name "gitlab.company.ltd" on 0.0.0.0:34080, ignored

вам же сказали.. Совпадение имен серверов, игнорируем.
Внимательно пересмотрите конфиги
Ответ написан
Комментировать
Ваш ответ на вопрос

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

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