用于HTTP和Web服务的Nginx,如何在自定义规则中重写位置

时间:2020-10-07 22:11:04

标签: nginx

我正在docker容器中运行theia,现在我使用主机子mydomain.com:port通过http输入,我想使用nginx作为反向代理来隐藏端口并使用nginx服务的https服务。 >

正如您之前看到的,我使用了一个子域,例如sub.mydomain.com

我在custom_rules.conf中创建了此自定义规则:

if ($host = "sub.mydomain.com") {
    set $PROXY_SCHEME "http";
    set $PROXY_DOMAIN_OR_IP "127.0.0.1";
    set $PROXY_TO_PORT 3000;
}

并且可以很好地处理HTTP请求,但是当Web服务尝试访问时出现错误 sub.mydomain.com/servicews

我将这些行添加到我的服务器子域的default_https.config中,现在可以正常使用Web服务路径:

location /servicews {
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header Host $host;

  proxy_pass http://ws-backend;

  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "Upgrade";
}

....

upstream ws-backend {
  ip_hash;
  server 127.0.0.1:myport;
}

问题是服务器在特定时间重写default_https.conf,第二个代码(位置*和上游*)将被删除。 我如何才能将此配置重写/转换为自定义规则?

0 个答案:

没有答案
相关问题