我有多个域指向同一个 IP。当且仅当页面不存在时,RedirectPermanent 才适用于所有域,并且我获得了我网站的 404 默认页面。如果我在浏览器中输入实际存在的页面,则重定向不起作用,因为我可以从指向该 IP 的所有域访问该页面。
因此,如果我输入 url domaintoredirect1.com/page/not/existing,我将获得 domainiwant.com/page/not/existing (重定向工作正常)
如果我输入 domaintoredirect1.com/page/existing ,则不会获得任何重定向,并且 URL 仍然是 domaintoredirect1.com/page/existing
为什么会发生这种情况?
我还想将 www 重定向到域名的非 www 版本,但在这种情况下重定向也不起作用:我得到了两个版本并且没有重定向。
我还想将另一个域扩展名 (.org 重定向到 .com),并将 www 重定向到非 www 版本的域,但在以下情况下重定向也不起作用:我得到的是 www...org 和 notwww...org,但没有重定向到 notwww...com。
在最后这些情况下,我检查了带有和不带有 www 的域名是否都注册了 A 记录(这可能是原因吗?)。在其他情况下(domainsiwanttoredirect),www 版本注册为 CNAME,我只能访问 www 版本(不带 www 的版本会重定向到 www 版本)。
这是VirtulHost 配置在 sites-available 中找到
<VirtualHost *:80>
ServerName www.domaintoredirect1.com
ServerAlias domaintoredirect1.com
Redirect permanent "/" "https://domainiwant.com/en/about-us/domaintoredirect1/"
</VirtualHost>
<VirtualHost *:80>
ServerName www.domaintoredirect2.com
ServerAlias domaintoredirect.com
Redirect permanent "/" "https://domainiwant.com/en/"
</VirtualHost>
<VirtualHost *:80>
ServerName www.domainiwant.org
ServerAlias domainiwant.org
Redirect permanent "/" "https://domainiwant.com/"
</VirtualHost>
<VirtualHost *:80>
ServerName www.domainiwant.com
Redirect permanent "/" "https://domainiwant.com/"
</VirtualHost>
<VirtualHost *:80>
ServerName domainiwant.com
Redirect permanent "/" "https://domainiwant.com/"
</VirtualHost>
<VirtualHost *:80>
ServerName default
DocumentRoot /var/www/html
<Location />
Require all denied
</Location>
</VirtualHost>
我正在添加ssl_配置文件还
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName website-ws.domainIwant.com
SSLCertificateFile /etc/ssl/certs/domainIwant.com.22092020.pem
SSLCertificateKeyFile /etc/ssl/private/domainIwant-com.key
SSLCipherSuite stuff...
SSLProtocol stuff...
SSLCipherSuite stuff...
#SSLProxyEngine on
<Location />
ProxyPass http://localhost:3000/
ProxyPassReverse http://localhost:3000/
</Location>
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# AllowOverride All
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerName www.domainToRedirect1.com
ServerAlias domainToRedirect1.com
SSLCertificateFile /etc/ssl/certs/domainToRedirect1.crt
SSLCertificateKeyFile /etc/ssl/private/nginx_kmdevel.key
SSLCipherSuite stuff
SSLProtocol stuff
SSLCipherSuite stuff
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# AllowOverride All
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerName www.domainIwant.com
SSLCertificateFile /etc/ssl/certs/domainIwant.com.22092020.pem
SSLCertificateKeyFile /etc/ssl/private/domainIwant-com.key
SSLCipherSuite stuff
SSLProtocol stuff
SSLCipherSuite stuff
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# AllowOverride All
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerName domainIwant.com
SSLCertificateFile /etc/ssl/certs/domainIwant.com.22092020.pem
SSLCertificateKeyFile /etc/ssl/private/domainIwant-com.key
SSLCipherSuite EECDH+AESGCM:EDH+AESGCM
SSLProtocol -all +TLSv1.3 +TLSv1.2 +TLSv1.1
SSLCipherSuite "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA256 EECDH+aRSA+SHA256 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS"
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# AllowOverride All
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerName www.domainIwant.it
ServerAlias domainIwant.it
SSLCertificateFile /etc/ssl/certs/domainIwant.it.2020.pem
SSLCertificateKeyFile /etc/ssl/private/domainIwant_2020.key
</VirtualHost>
<VirtualHost *:443>
ServerName www.domainToRedirect2.com
Include /etc/letsencrypt/options-ssl-apache.conf
ServerAlias domainToRedirect2.com
SSLCertificateFile /etc/letsencrypt/live/www.domainToRedirect2.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.domainToRedirect2.com/privkey.pem
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# AllowOverride All
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerName rcs.domainIwant.com
SSLCertificateFile /etc/ssl/certs/domainIwant.com.22092020.pem
SSLCertificateKeyFile /etc/ssl/private/domainIwant-com.key
SSLCipherSuite stuff
SSLProtocol stuff
SSLCipherSuite stuff
</VirtualHost>
</IfModule>
我究竟做错了什么?
我还会问服务器名称默认意思是,由于在 apache_conf 文件中我没有找到任何引用,因此我复制了Apache 配置归档也
DefaultRuntimeDir ${APACHE_RUN_DIR}
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf