我继承了一个环境,他们使用重写规则重定向 1400 多个 HTTPD/Apache 客户端。我想添加一个子域用于开发(因此是一个多级子域),并且我得到了“已通过 10 次内部重定向”的信息,我希望得到一点帮助。
他们目前拥有的适用于单级子域名的东西
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName client.domain.com
ServerAlias *.domain.com
VirtualDocumentRoot "/var/www/hosted/%1.0.domain.com"
Options FollowSymLinks
RewriteEngine On
CustomLog journald vhost
ErrorLog journald
<Location /app>
Require all denied
</Location>
# Redirect content that needs to be secure
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,QSA,NE,L]
</VirtualHost>
<VirtualHost *:443>
ServerName client.domain.com:443
ServerAlias *.domain.com
#DataDog Variables
SetEnv DD_SERVICE 'apache_pre-log'
SetEnv DD_ENV 'all-encompassing'
SetEnv DD_VERSION '1'
SetEnv DD_TRACE_SAMPLE_RATE '1'
# DocumentRoot "/var/www/hosted/www.easypeasyticketing.com"
#Doc Root
VirtualDocumentRoot "/var/www/hosted/%-3+.0.domain.com"
# Use separate log files for the SSL virtual host; note that LogLevel
# is not inherited from httpd.conf.
LogLevel warn
CustomLog logs/ssl_access_log.log vhost
ErrorLog logs/ssl_error_log.log
CustomLog logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/wildcard.domain.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/wildcard.domain.com.key
# Can be same as SSLCertificateFile
SSLCertificateChainFile /etc/pki/tls/certs/wildcard.domain.com.crt
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory "/var/www/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
Options FollowSymLinks
RewriteEngine On
# Ref: https://serverfault.com/a/644116
Alias /_error/ /var/www/errors/
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteCond /var/www/hosted/%1.domain.com/ !-d
RewriteRule ^ /_error/no_box_office.php [PT,L]
<Directory "/var/www/hosted">
Require all granted
# DirectoryIndex index.php
# FallbackResource /index.php
RewriteRule ^/?(index\.php)?$ /login [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /index.php [L]
</Directory>
<Location /app>
Require all denied
</Location>
<LocationMatch "/\.git.*">
Require all denied
</LocationMatch>
<Location /uploads>
Options FollowSymLinks
php_admin_value engine off
</Location>
</VirtualHost>
我的修改
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName client.dev.domain.com
ServerAlias *.dev.domain.com
VirtualDocumentRoot "/var/www/hosted/%1.0.domain.com"
Options FollowSymLinks
RewriteEngine On
CustomLog journald vhost
ErrorLog journald
<Location /app>
Require all denied
</Location>
# Redirect content that needs to be secure
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,QSA,NE,L]
</VirtualHost>
<VirtualHost *:443>
ServerName client.dev\domain.com:443
ServerAlias *.dev.domain.com
#DataDog Variables
SetEnv DD_SERVICE 'apache_pre-log'
SetEnv DD_ENV 'all-encompassing'
SetEnv DD_VERSION '1'
SetEnv DD_TRACE_SAMPLE_RATE '1'
#Doc Root
VirtualDocumentRoot "/var/www/hosted/%-3+.0.dev.domain.com"
# Use separate log files for the SSL virtual host; note that LogLevel
# is not inherited from httpd.conf.
LogLevel warn
CustomLog logs/ssl_access_log.log vhost
ErrorLog logs/ssl_error_log.log
CustomLog logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/wildcard.domain.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/wildcard.domain.com.key
# Can be same as SSLCertificateFile
SSLCertificateChainFile /etc/pki/tls/certs/wildcard.domain.com.crt
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory "/var/www/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
Options FollowSymLinks
RewriteEngine On
# Ref: https://serverfault.com/a/644116
Alias /_error/ /var/www/errors/
RewriteCond %{HTTP_HOST} ^(.*)\.dev\.domain\.com$ [NC]
RewriteCond /var/www/hosted/%1.dev.domain.com/ !-d
RewriteRule ^ /_error/no_box_office.php [PT,L]
<Directory "/var/www/hosted">
Require all granted
# DirectoryIndex index.php
# FallbackResource /index.php
RewriteRule ^/?(index\.php)?$ /login [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /index.php [L]
</Directory>
<Location /app>
Require all denied
</Location>
<LocationMatch "/\.git.*">
Require all denied
</LocationMatch>
<Location /uploads>
Options FollowSymLinks
php_admin_value engine off
</Location>
</VirtualHost>
答案1
我想到了这一点,以防其他人也遇到和我一样的多级子域名问题,
VirtualDocumentRoot "/var/www/hosted/%-3+.0.dev.domain.com"
需要进行更改以反映子域上的正确位置
VirtualDocumentRoot "/var/www/hosted/%-4+.0.dev.domain.com"
%-#
“光标”的位置是 1 为“.COM” 2 为“域” 3 为“子域” 4 为“子子域”