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 / 问题

问题[proxypass](server)

Martin Hope
Lunartist
Asked: 2022-01-28 18:05:23 +0800 CST

Nginx 重定向到 http://localhost

  • 0

情况简图

  • 我无法使用域地址,server_name因为我无法控制 DNS 服务器。我必须使用公共 IP 连接到我的 Web 服务器。
  • 所以我设置server_name为_;,但是当我请求http://firewall-public-ip:5000它重定向到http://localhost:5000.
  • 我通常可以打开其他不使用重定向的页面。例如,我可以访问http://firewall-public-ip:5000/login并登录,但它会重定向到,http://localhost:5000/login因为登录页面在登录后使用重定向。

nginx.conf:

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

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 4096;
    proxy_hide_header X-Powered-By;
    proxy_hide_header Server;

    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 5000;

    server_name _;
    server_name_in_redirect off;
    ssl_protocols TLSv1.2;

    location '/' {
        proxy_pass http://unix:/var/sockets/gunicorn.sock;
    }
  }
}

我该如何解决?同样,我不能使用此服务器的域地址。

*EDIT 添加了应用程序重定向

@blueprint.route('/')
def route_default():
    return redirect(url_for('authentication_blueprint.login'))


@blueprint.route('/login', methods=['GET', 'POST'])
def login():
    login_form = LoginForm(request.form)
    if 'login' in request.form:

        # read form data
        username = request.form['username']
        password = request.form['password']

        # Locate user
        user = Users.query.filter_by(username=username).first()

        # Check the password
        if user and verify_pass(password, user.password):

            login_user(user)
            return redirect(url_for('authentication_blueprint.route_default'))

        # Something (user or pass) is not ok
        return render_template('accounts/login.html',
                               msg='Wrong user or password',
                               form=login_form)

    if not current_user.is_authenticated:
        return render_template('accounts/login.html',
                               form=login_form)
    return redirect(url_for('home_blueprint.index'))

apps.authentication.__init__.py

from flask import Blueprint

blueprint = Blueprint(
    'authentication_blueprint',
    __name__,
    url_prefix=''
)
redirect nginx gunicorn proxypass
  • 1 个回答
  • 434 Views
Martin Hope
Alex44
Asked: 2021-11-14 08:26:41 +0800 CST

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

  • 2

我有一个服务器(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 个回答
  • 1006 Views
Martin Hope
user2341534
Asked: 2021-11-09 14:53:06 +0800 CST

Apache ProxyPass 到域的共享 IP 地址

  • 1

我有一个案例,我需要将域 (domain1.com) 代理传递到托管在共享 ip 地址 (192.168.168.168) 上的不同域 (domain2.com),但 domain2.com DNS 指向的不是共享 ip地址,所以 domain2.com 不能作为代理通行证,只能作为共享 ip 地址。

由于共享 ip 地址有多个主机名,是否有域或主机名配置选项可以与 proxypass 一起使用以强制在另一端进行虚拟主机查找?例如,使用这个 apache conf 文件将 domain1.com 代理到 192.168.168.168。

#Apache Reverse Proxy
SSLProxyEngine on

<Location />
ProxyPass http://192.168.168.168/
ProxyPassReverse http://192.168.168.168/
</Location>

是否可以进行任何更改来告诉在该 IP 上查找哪个域?

proxy reverse-proxy mod-proxy apache-2.4 proxypass
  • 1 个回答
  • 484 Views
Martin Hope
Reza Azimi
Asked: 2021-10-02 03:38:39 +0800 CST

使用 Apache 代理不通过端口转发

  • -1

我的服务器上有一些网站,其中很少有代理通行证,它们正在将一些端口传递给某个子域。但现在我正在尝试为 Webmin 添加另一个子域,但它不会转发到端口。

这是 site.conf:

    <VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName webmin.site.tld
    ProxyPreserveHost On

    <Proxy *>
        Order allow,deny
        Allow from all
    </Proxy>
    ProxyPass / http://'publicip':10000/
    ProxyPassReverse / http://'publicip':10000/

RewriteEngine On
RewriteCond %{REQUEST_URI} /api/v[0-9]+/(users/)?websocket [NC,OR]
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC,OR]
RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]

RewriteCond %{SERVER_NAME} =webmin.site.tld [OR]
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/webmin.site.tld/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/webmin.site.tld/privkey.pem
</VirtualHost>

这是我看到的屏幕截图: 这是我看到的屏幕截图

然后,如果我使用 10000 端口,我会看到: 然后,如果我使用 10000 端口,我会看到

因此,据我所知,Apache 不会将请求转发到端口 10000,并且使用相同的配置,我运行了一些网站,并且 bind9 没问题,证书也没问题。

我错过了什么?

apache-2.2 reverse-proxy proxypass webmin
  • 1 个回答
  • 340 Views
Martin Hope
Zareh Kasparian
Asked: 2021-09-30 04:25:54 +0800 CST

Nginx L4 代理适用于 HTTPS 但不适用于 HTTP

  • 0

我有以下配置作为 Nginx 上的 L4 代理,一切正常。

  stream {
 

    
    map $ssl_preread_server_name $name {
    hostnames;
    .ipchicken.com          $ssl_preread_server_name;
    .bbc.com                $ssl_preread_server_name;
    .bbc.co.uk              $ssl_preread_server_name;
    .bbci.co.uk             $ssl_preread_server_name;
    .neverssl.com           $ssl_preread_server_name;  #<-------
    
}


server {

    resolver 8.8.8.8;
    listen 443;
    ssl_preread on;
    proxy_connect_timeout 5s;
    proxy_pass $name:$server_port;
}

但是当请求 HTTP 站点时,例如“http://neverssl.com/”,Nginx 没有响应。对这个问题有任何想法吗?

proxy nginx reverse-proxy proxypass
  • 1 个回答
  • 268 Views
Martin Hope
Askirkela
Asked: 2021-08-11 02:26:46 +0800 CST

Nginx 正确地重写一个但不是另一个

  • 0

基本上,我正在尝试使用该proxy_pass指令来调用远程 API。

到目前为止,这是我得到的:

server {
  location /a {
    proxy_pass https://a.com;
    rewrite ^/a(.*)$ $1 break; # no trailing slash, defined in application code
  }
  location /b {
    proxy_pass https://b.com;
    rewrite ^/b(.*)$ $1 break; # no trailing slash, defined in application code
  }
  location / {
    # Rest of configuration
  }
}

我坚持可以location /a正常工作但location /b由于某种原因不能正常工作的事实(HTTP/404)。


location /b我尝试以这种方式使用斜杠

location /b/ {
  proxy_pass https://b.com/;
  rewrite ^/b/(.*)$ $1 break;
}

但这也不起作用。

非常欢迎任何帮助。

rewrite nginx proxypass
  • 1 个回答
  • 28 Views
Martin Hope
Michal
Asked: 2021-07-22 08:32:52 +0800 CST

Apache - ProxyPassReverse 具有相同主机的多个条目

  • 0

我们有这样的apache负载平衡配置:

<Proxy balancer://acluster>
BalancerMember ajp://10.10.10.1:8123 route=r1
BalancerMember ajp://10.10.10.2:8123 route=r2
</Proxy>
ProxyPass / balancer://acluster

#ProxyPassReverse / balancer://acluster
ProxyPassReverse / ajp://10.10.10.1:8123
ProxyPassReverse / ajp://10.10.10.2:8123

我试图找出拥有多个 ProxyPassReverse 条目而不是使用被注释掉的那一行的目的或效果是什么。谢谢

reverse-proxy proxypass
  • 1 个回答
  • 175 Views
Martin Hope
VIDesignz
Asked: 2021-06-15 15:33:49 +0800 CST

Apache ProxyPass 仅在基本 URL 上添加端口

  • 0

至少可以说这令人沮丧哈哈。

我已经在虚拟主机 443 下的 apache 中设置了 proxypass 和 proxypassreverse,以代理到在端口 8443 上的容器中运行的 nginx。

这就是我所做的一切

CustomLog /srv/apps/ktech-connect/log/apache/custom.log combined
ErrorLog /srv/apps/ktech-connect/log/apache/errors.log

SSLProxyEngine On
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off
ProxyPass        / https://127.0.0.1:8443/
ProxyPassReverse / https://127.0.0.1:8443/

当我点击任何网址(例如 example.com/page)时,它的工作原理应该如此但是当我转到 example.com 甚至 example.com/ 时,它会在 url 中显示从 apache 到 example.com:8443 的重定向。

我尝试添加 ProxyPreserveHost 但它什么也没做,还有很多其他选项。我只是不明白重定向的来源以及它仅在点击基本网址时发生的事实。

有什么想法吗?

virtualhost port nginx apache2 proxypass
  • 1 个回答
  • 172 Views
Martin Hope
Laksith
Asked: 2021-06-14 23:24:12 +0800 CST

nginx 拒绝对虚拟主机的所有请求。请求来自 nginx tcp 转发器

  • 3

摘要 - 需要将白名单 ips 添加到 mysite1.example.com。现在,当它们被添加时,它不起作用,因为每个请求都来自负载平衡器服务器。

我正在使用带有上游后端的前置 Nginx 主机进行设置,以将端口 443 上的所有 tcp 数据包负载平衡到后端服务器。

运行 nginx 的 Loadbalancer 服务器的 nginx 配置 - 服务器 C 如下

stream {
        upstream stream_backend {
                hash $remote_addr consistent;
                server 10.15.15.3:443;   ## server A
                server 10.15.15.9:443;   ## server B
        }


        server {
                listen     443;
                proxy_pass stream_backend;
                proxy_timeout 5s;
                proxy_connect_timeout 5s;
        }
}

服务器 A 和服务器 B 具有以下 nginx.conf。它们是带有应用程序的相同服务器。

它有两个虚拟主机在每个运行。他们工作正常。

http {

    server {
        server_name mysite1.example.com;
        listen *:443 ssl;
        listen [::]:443 ssl;
        
        allow 123.45.85.220; # this seems not working
        deny all; # only this is working

        
        location ^~ /static/ {
            ...
        }
        ...
        
        ssl_certificate        file.pem;
        ssl_certificate_key    file.key;
    }


    server {
        server_name mysite2.example.com;
        listen *:443 ssl;
        listen [::]:443 ssl;
        
        
        location /somethin {
            ...
        }
        location /something2{
            ...
        }
        
        ssl_certificate        file.pem;
        ssl_certificate_key    file.key;
    }
}

我需要的是将虚拟主机 mysite1.example.com 的几个 ip 列入白名单。我面临的问题是在服务器 A 和 B 上运行的 nginx 将负载均衡器 Ip 视为客户端 Ip。所以当尝试添加允许 IP 时;全部否认。不适用于任何主机,因为它在所有请求上都将负载均衡器 IP 作为客户端 IP。

有人可以指导我添加代理 IP 配置以实现上述设置运行良好。除 IP 白名单问题外,设置已完成。

ps Ssl 终止发生在后端服务器、服务器 A 和服务器 B

我在网上搜索并发现这些很有帮助,但仍然无法弄清楚如何让它全部工作。

https://stackoverflow.com/questions/40873393/nginx-real-client-ip-to-tcp-stream-backend https://www.cyberciti.biz/faq/nginx-redirect-backend-traffic-based-upon -客户端IP地址/

load-balancing virtualhost nginx proxypass
  • 3 个回答
  • 842 Views
Martin Hope
seinecle
Asked: 2021-05-17 03:00:09 +0800 CST

在 nginx 中删除 Java 应用程序的子路径(上下文根)

  • -1

该应用程序位于 Payara 服务器上并具有上下文根nocodeapp-web-front-1.0

我不想在 url 中有这个上下文根。此 nginx 配置为应用程序的页面提供了预期的结果index(它位于https://test.nocodefunctions.com):

upstream payara {
    least_conn;

    server localhost:8080 max_fails=3 fail_timeout=5s;
    server localhost:8181 max_fails=3 fail_timeout=5s;
}
server {
    if ($host = test.nocodefunctions.com) {
        return 301 https://$host$request_uri;
    }


    listen        80;
    access_log /var/log/nginx/payara-access.log;
    error_log /var/log/nginx/payara-error.log;
    
    client_max_body_size 100M;
    server_name   test.nocodefunctions.com;
    return        301 https://$host$request_uri;


}

server {
    listen        443 ssl;
    server_name   test.nocodefunctions.com;
    client_max_body_size 100M;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";

    location /nocodeapp-web-front-1.0 {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-Proto https;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_no_cache $cookie_nocache  $arg_nocache$arg_comment;
            proxy_no_cache $http_pragma     $http_authorization;
            proxy_cache_bypass $cookie_nocache $arg_nocache $arg_comment;
            proxy_cache_bypass $http_pragma $http_authorization;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $host:$server_port;
            add_header Access-Control-Allow-Origin *;
            proxy_set_header Access-Control-Allow-Origin *;
            proxy_pass http://payara$request_uri;
    }
    
    location = / {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-Proto https;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_pass http://payara/nocodeapp-web-front-1.0$request_uri$is_args$args;
    }

    ssl_certificate /etc/letsencrypt/live/xxxxxx/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/xxxxxx/privkey.pem; # managed by Certbot
}

但是,当我们通过单击“开始”按钮在应用程序中导航时,页面/choosefunction.html显示为:

https://test.nocodefunctions.com/nocodeapp-web-front-1.0/choosefunction.html

...子路径nocodeapp-web-front-1.0再次出现?

我怎样才能得到:

https://test.nocodefunctions.com/choosefunction.html

注意:我已经检查了这两个问题1和2,它们对我不起作用

java glassfish nginx proxypass
  • 1 个回答
  • 214 Views

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