虚拟主机不工作(Mod_proxy、Proxmox)

发布于 2024-12-25 22:45:05 字数 4547 浏览 3 评论 0原文

首先,我使用 Proxmox 虚拟化多台机器。 现在我希望我的主机根据服务器名称相应地重定向流量。 我的设置曾经工作过一次,但现在不知何故无法工作。

我的默认主机:

00_proxmox_domain_com.conf

NameVirtualHost *:80
<VirtualHost *:80>
ServerName proxmox.domain.com
ServerName *.proxmox.domain.com
#RewriteLog "/root/rewrite.log"
#RewriteLogLevel 10
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
RewriteCond %{REQUEST_URI} !^/nrd/
RewriteCond %{REQUEST_URI} !^/images/
RewriteCond %{REQUEST_URI} !^/css/
RewriteCond %{REQUEST_URI} !^/javascript/
RewriteCond %{REQUEST_URI} !^/vncterm/
RewriteCond %{REQUEST_URI} !^/.*\.js$
RewriteCond %{REQUEST_URI} !^/login.pl$
RewriteCond %{HTTP_HOST} ^proxmox\.domain\.com$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [L,R]
</VirtualHost>

然后我有几个类似的虚拟主机,(目前只有这一个被激活) 这应该将访问者发送到 IP 192.168.1.13 的虚拟服务器上的 PHPMyAdmin

02_pma_domain_com.conf

<VirtualHost *:80>
ServerName pma.domain.com
ServerName *.pma.domain.com

ProxyRequests Off

ProxyPreserveHost On

<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>

ProxyPass / http://192.168.1.13/
ProxyPassReverse / http://192.168.1.13/
</VirtualHost>

并且有 Proxmox 虚拟主机文件

pve.conf

<IfModule mpm_prefork_module>
StartServers 2
MinSpareServers 1 
MaxSpareServers 2
MaxClients          50
MaxRequestsPerChild 30
</IfModule>

  ServerName localhost
  ServerSignature Off
  ServerTokens Prod
  ServerAdmin root
  AddDefaultCharset On

  # Hint: Ajax use KeepAlive, which in effect disables MaxRequestsPerChild,
  # so we need to disable KeepAlive to prevent exhaustive memory usage, or
  # at least make sure that periodic updaters interval > KeepAliveTimeout 
  KeepAlive Off

  DocumentRoot /usr/share/pve-manager/root
  <Directory />
Options FollowSymLinks
AllowOverride None
  </Directory>

  <Directory /usr/share/pve-manager/root>
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
  </Directory>

  ErrorLog /var/log/apache2/error.log

  LogLevel warn

  # do not log access to our ajax services
  SetEnvIf Request_URI "^/ws/" dontlog

  CustomLog /var/log/apache2/access.log combined env=!dontlog 

  Alias /images/  /usr/share/pve-manager/images/
  Alias /css/ /usr/share/pve-manager/css/
  Alias /javascript/ /usr/share/javascript/
  Alias /vncterm/ /usr/share/vncterm/

  # avoid authentication when accessing favicon
  Alias /favicon.ico /usr/share/pve-manager/images/favicon.ico

  PerlModule Embperl
  EMBPERL_SESSION_ARGS "config=DB_File Lock=Semaphore"

  AddType text/html .epl

  PerlRequire /usr/share/pve-manager/root/startup.pl

  PerlSetVar PVESatisfy any     
  PerlSetVar PVEPath /  
  PerlSetVar PVELoginScript /login.pl

  PerlTransHandler PVE::URLRewrite

  Alias /nrd/ /__no_real_dir__/

  <Directory "/usr/share/pve-manager/root">
  AuthType PVE::AuthCookieHandler
  AuthName PVE
  PerlSetVar PVECookieName PVEAuthCookie
  #PerlSetVar AuthCookieDebug 5

  PerlAuthenHandler PVE::AuthCookieHandler->authenticate
  PerlAuthzHandler PVE::AuthCookieHandler->authorize

  require group root

  DirectoryIndex index.htm index.pl

  <FilesMatch ".*\.htm$">
EMBPERL_APPNAME PVE
    EMBPERL_SYNTAX EmbperlBlocks
    EMBPERL_OBJECT_BASE base.epl
EMBPERL_INPUT_ESCMODE 0
EMBPERL_ESCMODE 0
    SetHandler  perl-script
    PerlHandler Embperl::Object
    Options     ExecCGI
  </FilesMatch>
  <FilesMatch ".*\.epl$">
    Order allow,deny
    Deny From all
  </FilesMatch>
  <FilesMatch ".*\.pl$">
    SetHandler perl-script
PerlHandler ModPerl::Registry
    Options +ExecCGI
  </FilesMatch>

</Directory>

<Location /nrd/LOGIN>
  AuthType PVE::AuthCookieHandler
  AuthName PVE
  PerlSetVar PVECookieName PVEAuthCookie
  #PerlSetVar AuthCookieDebug 5
  SetHandler perl-script
  PerlHandler PVE::AuthCookieHandler->login
</Location>

<Location /ws/>
  SetHandler perl-script
  PerlHandler $PVE::HTMLServices::Obj->handler
</Location>

<VirtualHost *:443>
SSLEngine on
SSLProtocol all -SSLv2
SSLCertificateFile /etc/pve/pve-ssl.pem
SSLCertificateKeyFile /etc/pve/pve-ssl.key

RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]

</VirtualHost>

如果您看到明显的错误,请告诉我。

如果你有一个可以正常安装的 proxmox 如果你能给我你的 pve.conf 将会有帮助 如果您的虚拟主机正在运行,那么这些文件之一将是最受欢迎的。

我尝试了多种方法来解决该问题,但没有任何效果。

For starters I use Proxmox to virtualize several machines.
Now I want my main machine to redirect the traffic accordingly based on the servername.
I had the setup working once, but now somehow it won't work.

my default host:

00_proxmox_domain_com.conf

NameVirtualHost *:80
<VirtualHost *:80>
ServerName proxmox.domain.com
ServerName *.proxmox.domain.com
#RewriteLog "/root/rewrite.log"
#RewriteLogLevel 10
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
RewriteCond %{REQUEST_URI} !^/nrd/
RewriteCond %{REQUEST_URI} !^/images/
RewriteCond %{REQUEST_URI} !^/css/
RewriteCond %{REQUEST_URI} !^/javascript/
RewriteCond %{REQUEST_URI} !^/vncterm/
RewriteCond %{REQUEST_URI} !^/.*\.js$
RewriteCond %{REQUEST_URI} !^/login.pl$
RewriteCond %{HTTP_HOST} ^proxmox\.domain\.com$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [L,R]
</VirtualHost>

Then I have several similar virtualhost, (currently only this one is activated)
This should send the visitor to PHPMyAdmin on virtual server with IP 192.168.1.13

02_pma_domain_com.conf

<VirtualHost *:80>
ServerName pma.domain.com
ServerName *.pma.domain.com

ProxyRequests Off

ProxyPreserveHost On

<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>

ProxyPass / http://192.168.1.13/
ProxyPassReverse / http://192.168.1.13/
</VirtualHost>

And there is the Proxmox virtual hostfile

pve.conf

<IfModule mpm_prefork_module>
StartServers 2
MinSpareServers 1 
MaxSpareServers 2
MaxClients          50
MaxRequestsPerChild 30
</IfModule>

  ServerName localhost
  ServerSignature Off
  ServerTokens Prod
  ServerAdmin root
  AddDefaultCharset On

  # Hint: Ajax use KeepAlive, which in effect disables MaxRequestsPerChild,
  # so we need to disable KeepAlive to prevent exhaustive memory usage, or
  # at least make sure that periodic updaters interval > KeepAliveTimeout 
  KeepAlive Off

  DocumentRoot /usr/share/pve-manager/root
  <Directory />
Options FollowSymLinks
AllowOverride None
  </Directory>

  <Directory /usr/share/pve-manager/root>
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
  </Directory>

  ErrorLog /var/log/apache2/error.log

  LogLevel warn

  # do not log access to our ajax services
  SetEnvIf Request_URI "^/ws/" dontlog

  CustomLog /var/log/apache2/access.log combined env=!dontlog 

  Alias /images/  /usr/share/pve-manager/images/
  Alias /css/ /usr/share/pve-manager/css/
  Alias /javascript/ /usr/share/javascript/
  Alias /vncterm/ /usr/share/vncterm/

  # avoid authentication when accessing favicon
  Alias /favicon.ico /usr/share/pve-manager/images/favicon.ico

  PerlModule Embperl
  EMBPERL_SESSION_ARGS "config=DB_File Lock=Semaphore"

  AddType text/html .epl

  PerlRequire /usr/share/pve-manager/root/startup.pl

  PerlSetVar PVESatisfy any     
  PerlSetVar PVEPath /  
  PerlSetVar PVELoginScript /login.pl

  PerlTransHandler PVE::URLRewrite

  Alias /nrd/ /__no_real_dir__/

  <Directory "/usr/share/pve-manager/root">
  AuthType PVE::AuthCookieHandler
  AuthName PVE
  PerlSetVar PVECookieName PVEAuthCookie
  #PerlSetVar AuthCookieDebug 5

  PerlAuthenHandler PVE::AuthCookieHandler->authenticate
  PerlAuthzHandler PVE::AuthCookieHandler->authorize

  require group root

  DirectoryIndex index.htm index.pl

  <FilesMatch ".*\.htm$">
EMBPERL_APPNAME PVE
    EMBPERL_SYNTAX EmbperlBlocks
    EMBPERL_OBJECT_BASE base.epl
EMBPERL_INPUT_ESCMODE 0
EMBPERL_ESCMODE 0
    SetHandler  perl-script
    PerlHandler Embperl::Object
    Options     ExecCGI
  </FilesMatch>
  <FilesMatch ".*\.epl$">
    Order allow,deny
    Deny From all
  </FilesMatch>
  <FilesMatch ".*\.pl$">
    SetHandler perl-script
PerlHandler ModPerl::Registry
    Options +ExecCGI
  </FilesMatch>

</Directory>

<Location /nrd/LOGIN>
  AuthType PVE::AuthCookieHandler
  AuthName PVE
  PerlSetVar PVECookieName PVEAuthCookie
  #PerlSetVar AuthCookieDebug 5
  SetHandler perl-script
  PerlHandler PVE::AuthCookieHandler->login
</Location>

<Location /ws/>
  SetHandler perl-script
  PerlHandler $PVE::HTMLServices::Obj->handler
</Location>

<VirtualHost *:443>
SSLEngine on
SSLProtocol all -SSLv2
SSLCertificateFile /etc/pve/pve-ssl.pem
SSLCertificateKeyFile /etc/pve/pve-ssl.key

RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]

</VirtualHost>

If you see an obvious error, please tell me.

If you have a working install of proxmox it would help if you could give me your pve.conf
And if you've got the virtualhosts working one of those files would be most welcome.

I've tried several things to solve the problem, without any effect.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠檬心 2025-01-01 22:45:05

找到了,感谢:
Apache 2.2 忽略 VirtualDocumentRoot VirtualHosts?

应该只有一个 ServerName,并且可以不包含任何通配符,
你应该使用 ServerAlias 来代替;)

Found it, thanks to:
Apache 2.2 ignoring VirtualDocumentRoot VirtualHosts?

There should be only one ServerName, and it can't contain any wildcards,
you should use ServerAlias instead ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文