简体   繁体   English

网络面板中的虚拟主机配置不起作用

[英]vhost config in cyberpanel is not working

There is vhost config, which should be reverse proxy to the flask application, and is not working.有虚拟主机配置,它应该是 flask 应用程序的反向代理,但无法正常工作。 Below is the vhost config.下面是虚拟主机配置。 Flask application is running on port 5000. Flask 应用程序正在端口 5000 上运行。

Added rewrite in both the context and outside, even then it's not working.在上下文和外部都添加了重写,即使那样它也不起作用。 Below config always gives the error 500.下面的配置总是给出错误 500。

vhDomain                  $VH_NAME
vhAliases                 www.$VH_NAME
enableGzip                1
enableIpGeo               1

index  {
  useServer               0
  indexFiles              index.php, index.html
}

errorlog $VH_ROOT/logs/$VH_NAME.error_log {
  useServer               0
  logLevel                WARN
  rollingSize             10M
}

accesslog $VH_ROOT/logs/$VH_NAME.access_log {
  useServer               0
  logFormat               "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i""
  logHeaders              5
  rollingSize             10M
  keepDays                10  
  compressArchive         1
}

extprocessor pythonflask1709 {
  type                    proxy
  address                 127.0.0.1:5000
  maxConns                200
  pcKeepAliveTimeout      60
  initTimeout             20
  retryTimeout            0
  respBuffer              0
}

scripthandler {
  add proxy:pythonflask1709 html
}

module cache {
 storagePath /usr/local/lsws/cachedata/$VH_NAME
}

rewrite  {
  enable 1
  autoLoadHtaccess 1
  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  REWRITERULE ^(.*)$ HTTPS://127.0.0.1:5000/$1 [P]
}

context / {
  type                    proxy
  handler                 pythonflask1709
  addDefaultCharset       off
 
  rewrite  {
    enable 1
    autoLoadHtaccess 1
    RewriteEngine On
    RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    REWRITERULE ^(.*)$ HTTP://127.0.0.1:5000/$1 [P]
  }
}

For reverse proxy, you have created a Web Server External App named pythonflask1709 which is good.对于反向代理,您创建了一个名为 pythonflask1709 的 Web 服务器外部应用程序,这很好。 The next step is to set up a context, rewrite rules, or Script Handlers.下一步是设置上下文、重写规则或脚本处理程序。

Context method上下文方法

context / {
  type                    proxy
  handler                 demo
  addDefaultCharset       off
}

Rewrite method重写方法

REWRITERULE ^(.*)$ HTTP://pythonflask1709/$1 [P,L,E=PROXY-HOST:WWW.EXAMPLE.COM]

As you can see the above rule, use web server name pythonflask1709 in the rule instead of 127.0.0.1:5000, also please substitute WWW.EXAMPLE.COM with your real domain name.如您所见,在规则中使用 web 服务器名称pythonflask1709而不是 127.0.0.1:5000,也请用您的真实域名替换 WWW.EXAMPLE.COM。

Both should work, but please do not apply both methods at the same time.两者都应该有效,但请不要同时应用这两种方法。

Another solution is to run WSGI APP directly without proxy.另一种解决方案是直接运行WSGI APP,无需代理。 More, https://openlitespeed.org/kb/python-wsgi-applications/#Set_up_Flask_with_a_Virtual_Environment更多, https://openlitespeed.org/kb/python-wsgi-applications/#Set_up_Flask_with_a_Virtual_Environment

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM