AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1083473
Accepted
Alex44
Alex44
Asked: 2021-11-14 08:26:41 +0800 CST2021-11-14 08:26:41 +0800 CST 2021-11-14 08:26:41 +0800 CST

通过 NGINX 的驾驶舱 - 设置使其他服务无法访问

  • 772

我有一个服务器(Ubuntu-Server),带有一些基于 Docker 的服务器(Gitlab、Redmine)和 NGINX 作为代理。

gitlab.<myserver>    => NGINX -> <docker-net-ip>:port => Gitlab-container  
redmine.<myserver>   => NGINX -> <docker-net-ip>:port => Redmine-container
                                                         SQL-container  
                                                         Certbot  

这就像一个魅力。现在我想通过 Cockpit Web Service 扩展我的服务器:

cockpit.<myserver>   => NGINX -> localhost:9090       => Cockpit running on the server  
gitlab.<myserver>    => NGINX -> <docker-net-ip>:port => Gitlab-container  
redmine.<myserver>   => NGINX -> <docker-net-ip>:port => Redmine-container
                                                         SQL-container  
                                                         Certbot  

我为驾驶舱添加了一个额外的 NGINX 规则(对应于https://github.com/cockpit-project/cockpit/wiki/Proxying-Cockpit-over-NGINX),然后驾驶舱可用,但 Redmine 和 Gitlab 都没有。如果我删除规则,反之亦然。

在/etc/nginx/sites-available/和/etc/nginx/sites-enabled/中存储了以下 NGINX 规则:

gitlab.<我的服务器>

server {

    listen 80;
    listen [::]:80;

    server_name gitlab.<myserver>;

    location / {
        proxy_pass         http://<docker-net-ip>:port;
        proxy_buffering    off;
        proxy_set_header   X-Real-IP       $remote_addr;
    }
}

redmine.<我的服务器>

server {

    listen 80;
    listen [::]:80;

    server_name redmine.<myserver>;

    location / {
        proxy_pass         http://<docker-net-ip>:port;
        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;
    }
}

现在我添加了:
cockpit.<myserver>

server {
    listen         80;
    listen         443 ssl;

    server_name    cockpit.<myserver>;

    location / {
        # Required to proxy the connection to Cockpit
        proxy_pass https://127.0.0.1:9090;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Proto $scheme;

        # Required for web sockets to function
        proxy_http_version 1.1;
        proxy_buffering off;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        # Pass ETag header from Cockpit to clients.
        # See: https://github.com/cockpit-project/cockpit/issues/5239
        gzip off;
    }
}

和/etc/cockpit/cockpit.conf

[WebService]
Origins = https://cockpit.<myserver> 127.0.0.1:9090
ProtocolHeader = X-Forwarded-Proto

[Log]
Fatal = /var/log/cockpit.log

[Session]
IdleTimeout=15

这里缺少什么?

proxy nginx proxypass cockpit
  • 1 1 个回答
  • 1006 Views

1 个回答

  • Voted
  1. Best Answer
    Alex44
    2021-11-15T06:23:35+08:002021-11-15T06:23:35+08:00

    这里缺少什么?

    并非所有设备都会出现此问题。有些人显示“此连接不安全”。对于 redmine 和 gitlab。但驾驶舱没有。现在谜题的解决方案是,Gitlab 和 Redmine 的规则不完整,https 请求无处可去。

    缺少端口 443 (https) 的规则。现在我把块变成了两个:

    1. 将http请求重定向到https
    2. 监听 https 请求并将它们转发到应用程序

    现在看起来像这样:

    /etc/nginx/sites-available/gitlab.<myserver>链接到/etc/nginx/sites-enabled/gitlab.<myserver>

    # redirect http request to https while keeping the request uri
    server {
    
        listen 80;
        listen [::]:80;
    
        server_name gitlab.<myserver>;
    
        return 301 https://gitlab.<myserver>$request_uri;
    }
    
    # https requests will forwarded to the server application
    server {
    
        listen 443 ssl;
        listen [::]:443 ssl;
    
        server_name gitlab.<myserver>;
    
        location / {
            proxy_pass         http://<docker-net-ip>:<port>;
            proxy_buffering    off;
            proxy_set_header   X-Real-IP       $remote_addr;
    
            # Note: You should disable gzip for SSL traffic.
            # See: https://bugs.debian.org/773332
            gzip off;
        }
    }
    
    

    /etc/nginx/sites-available/redmine.<myserver>链接到/etc/nginx/sites-enabled/redmine.<myserver>

    # redirect http request to https while keeping the request uri
    server {
    
        listen 80;
        listen [::]:80;
    
        server_name redmine.<myserver>;
    
        return 301 https://redmine.<myserver>$request_uri;
    }
    
    # https requests will forwarded to the server application
    server {
    
        listen 443 ssl;
        listen [::]:443 ssl;
    
        server_name redmine.<myserver>;
    
        location / {
            proxy_pass         http://<docker-net-ip>:<port>;
            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;
    
            # Note: You should disable gzip for SSL traffic.
            # See: https://bugs.debian.org/773332
            gzip off;
        }
    }
    
    

    /etc/nginx/sites-available/cockpit.<myserver>链接到/etc/nginx/sites-enabled/cockpit.<myserver>

    server {
        listen         80;
        listen         443 ssl;
    
        server_name    cockpit.<myserver>;
    
        location / {
            # Required to proxy the connection to Cockpit
            proxy_pass https://127.0.0.1:9090;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-Proto $scheme;
    
            # Required for web sockets to function
            proxy_http_version 1.1;
            proxy_buffering off;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
    
            # Pass ETag header from Cockpit to clients.
            # See: https://github.com/cockpit-project/cockpit/issues/5239
            gzip off;
        }
    }
    

    和/etc/cockpit/cockpit.conf

    [WebService]
    Origins = https://cockpit.<myserver> 127.0.0.1:9090
    ProtocolHeader = X-Forwarded-Proto
    
    [Log]
    Fatal = /var/log/cockpit.log
    
    [Session]
    IdleTimeout=15
    

    并且为了完成:
    /etc/nginx/sites-available/default链接到/etc/nginx/sites-enabled/default

    ##
    # You should look at the following URL's in order to grasp a solid understanding
    # of Nginx configuration files in order to fully unleash the power of Nginx.
    # https://www.nginx.com/resources/wiki/start/
    # https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
    # https://wiki.debian.org/Nginx/DirectoryStructure
    #
    # In most cases, administrators will remove this file from sites-enabled/ and
    # leave it as reference inside of sites-available where it will continue to be
    # updated by the nginx packaging team.
    #
    # This file will automatically load configuration files provided by other
    # applications, such as Drupal or WordPress. These applications will be made
    # available underneath a path with that package name, such as /drupal8.
    #
    # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
    ##
    
    # Default server configuration
    #
    server {
        listen 80 default_server;
        listen [::]:80 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;
    
        error_log /opt/logs/certbot_error debug;
    }
    
    • 2

相关问题

  • 持续监控许多服务器运行状况的简单方法?

  • Web 代理脚本与 http 代理的效率?

  • 为将笔记本电脑带回家的用户模拟公司代理

  • 什么是 Microsoft 代理客户端(MSP 客户端)

  • 使用大量 javascript 的页面上的鱿鱼速度很慢

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve