Maison  >  Questions et réponses  >  le corps du texte

Comment écrire la configuration du proxy inverse nginx

L'effet que je souhaite :

http://hostname/proxy/3000
http://127.0.0.1:3000

http://hostname/proxy/3000/anything
http://127.0.0.1:3000/anything

Il y a une condition : le port est changé

J'ai essayé

location ~ /proxy/(\d+) {
        proxy_pass http://127.0.0.1:;
        rewrite ^/(.*)$ / break;
    }

Mais la réécriture a des problèmes, quelle que soit la façon dont elle est écrite

Comment écrire dans la configuration nginx, en attente en ligne~

滿天的星座滿天的星座2712 Il y a quelques jours438

répondre à tous(1)je répondrai

  • 漂亮男人

    漂亮男人2017-05-16 17:28:53

    proxy_pass 的文档里有讲:location 使用了正则后,proxy_pass La partie URI dans les paramètres suivant la directive sera ignorée. Vous pouvez utiliser la configuration suivante pour réaliser indirectement la fonction souhaitée :

    server {
        listen       80;
        server_name  localhost;
    
        location /proxy/ {
            rewrite ^/proxy/(\d+)/(.*)  /internal?port=&url= last;
        }
    
        location /internal {
            internal;
            proxy_pass http://127.0.0.1:$arg_port/$arg_url;
        }
    }   
    

    répondre
    0
  • Annulerrépondre