假设我同时使用pytest.main()
和pytest
URL。如果将我的VirtualHost目录设置为仅接受www.example
,则意味着使用example.com
的任何人都将无法访问该网站。
我希望使用example.com
或www.example.com
的任何人都能访问我的网站。我该怎么解决?
www.example.com
答案 0 :(得分:1)
同时使用ServerName
和ServerAlias
这是我用于模板的内容-
对于非SSL-
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www-example.com
<directory /var/www-example.com>
Options All
AllowOverride All
Require all granted
</directory>
ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
</VirtualHost>
并使用LetsEncrypt的SSL-
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
RewriteEngine on
RewriteRule ^/(.*)$ https://www.example.com/$1 [R,L]
</VirtualHost>
<VirtualHost 10.0.2.5:443>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster@example.com
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
CustomLog ${APACHE_LOG_DIR}/ssl_request_log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
DocumentRoot /var/www-example.com
<directory /var/www-example.com>
Options All
AllowOverride All
Require all granted
</directory>
ErrorLog ${APACHE_LOG_DIR}/ssl-example.com-error.log
CustomLog ${APACHE_LOG_DIR}/ssl-example.com-access.log combined
</VirtualHost>