提问人:xtrose Media Studio 提问时间:11/17/2023 更新时间:11/17/2023 访问量:14
VM 上的 apache2 重定向到 VM 上的本地 IP
apache2 in on VM redirects to local IP on VM's
问:
我的设置中的 apache2 遇到了一些问题。 对于这些,我将 proxmox 与多个域、多个 VM 和一个公共 IP 一起使用。 为了分发来自公共 IP 的请求,我在 proxmox 主机上安装了 apache2。 在VM上,我还安装了apache2。
现在的问题是,当 VM 上的 apache2 服务器执行重定向时,重定向会转到本地 IP,而不是主机。 为此,我在我的 Web 应用程序的根目录中设置了一个 .htaccess 文件。
Proxmox 主机上的 Apache2 设置
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName www.example.com
Header add "Host" "www.example.com"
RequestHeader set "Host" "www.example.com"
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin [email protected]
ServerName www.example.com
ServerAlias www.example.com
RewriteEngine On
RewriteCond %{HTTP_HOST} !=www.example.com [NC]
RewriteRule ^(.*)$ https://www.example.com%{REQUEST_URI} [R=301,L]
SSLProxyEngine On
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off
ProxyPass / http://10.10.10.101:80/
ProxyPassReverse / http://10.10.10.101:80/
Header add "Host" "www.example.com"
RequestHeader set "Host" "www.example.com"
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
</IfModule>
VM 上的 apache2 设置侦听 10.10.10.101
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName www.example.com
ServerAlias www.example.com
Header add "Host" "www.example.com"
RequestHeader set "Host" "www.example.com"
DocumentRoot /var/www/www.example/current/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<Directory /var/www/www.example/current/*/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
我的 Web 应用程序根目录上的 .htacces 文件
<If "%{REQUEST_URI} =~ m#^/admin#">
AuthUserFile "/var/www/www.example/.htpasswd"
AuthType Basic
AuthName "Restricted Area"
Require valid-user
</If>
<If "%{REQUEST_URI} =~ m#^/store#">
AuthUserFile "/var/www/www.example/.htpasswd"
AuthType Basic
AuthName "Restricted Area"
Require valid-user
</If>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.map|\.png|\.jpg|\.jpeg|\.gif|\.svg|\.webp|\.woff|\.woff2|\.ttf|\.otf|\.eot|\.pdf|\.zip)$ [NC]
RewriteRule .* index.php [L,QSA]
</IfModule>
<IfModule authz_core_module>
<FilesMatch "(composer\.json|composer\.lock|config\.inc\.php|config\.local\.php)$">
Require all denied
</FilesMatch>
</IfModule>
因此,当我在应用程序中调用子指令时,id 也应该使用 der 根目录中的 index.php。
核心目录上的示例。 在调用“www.example.com/core/”时,apache2 会重定向到 www.example.com。 在调用“www.example.com/core”时,apache2 重定向到内部 IP 10.10.10.101,末尾不带斜杠。
我现在有一天正在测试这个,不喜欢解决方案。 也许任何人都可以让我解决这个问题。
谢谢
我尝试过 SetHeaders、SetEnv 等等。 谢谢你的帮助。
答: 暂无答案
评论