虚拟主机配置文件未将 http 重定向到 https
virtual host config file not redirecting http to https
我无法将 http 重定向到 https,但所有 information/tutorials 和描述均无效。我们在 Debian 机器上使用 Apache2,这是 conf 文件
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
ServerName assets.xxx.it
ServerAlias assets.xxx.it
DocumentRoot /var/www/assets/eit_resource_manager_frontend/build
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
RedirectMatch ^(.*)$ https://assets.xxx.it
</VirtualHost>
<VirtualHost *:443>
ServerName assets.xxx.it
ServerAlias assets.xxx.it
Protocols h2 http/1.1
<Directory "/var/www/assets/eit_resource_manager_frontend/build">
RewriteEngine on
#Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
#Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.theml [L]
</Directory>
# SSL Configuration
# Other Apache Configuration
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/assets.xxx.it/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/assets.xxx.it/privkey.pem
</VirtualHost>
对文件进行任何更改后,我重新启动了服务器,但 HTTP 未重定向到 HTTPS。我尝试了不同的实现方式,但结果却很差。
有关详细信息,登录页面位于 assets.xxx.it/login 并且从“/”到“/login”的重定向在应用程序内部处理(通过 React Router)
有什么建议吗?
在使用 certbot
和 Apache 插件创建 SSL 证书时,会创建一个 SSL 配置文件,因此我们想出了一个由我们创建的 vh 80 文件,一个由我们创建的 vh 443 文件我们,以及创建证书时生成的 80 和 443 文件。
如前所述,此文件包含端口 80 和 443 的说明,但是,尽管我们在创建证书时要求重定向,但此 conf
文件中没有这样的说明。所以我们添加了 RedirectMatch
指令并且它起作用了。我们还删除了我们创建的 vh 443 conf 文件,它继续工作。
经过其他搜索我也明白了 Directory
标签中的 RewriteCond
和 RewriteRule
如果您想使用 .htaccess
文件用于更精细控制的 repo 文件夹。
我无法将 http 重定向到 https,但所有 information/tutorials 和描述均无效。我们在 Debian 机器上使用 Apache2,这是 conf 文件
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
ServerName assets.xxx.it
ServerAlias assets.xxx.it
DocumentRoot /var/www/assets/eit_resource_manager_frontend/build
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
RedirectMatch ^(.*)$ https://assets.xxx.it
</VirtualHost>
<VirtualHost *:443>
ServerName assets.xxx.it
ServerAlias assets.xxx.it
Protocols h2 http/1.1
<Directory "/var/www/assets/eit_resource_manager_frontend/build">
RewriteEngine on
#Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
#Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.theml [L]
</Directory>
# SSL Configuration
# Other Apache Configuration
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/assets.xxx.it/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/assets.xxx.it/privkey.pem
</VirtualHost>
对文件进行任何更改后,我重新启动了服务器,但 HTTP 未重定向到 HTTPS。我尝试了不同的实现方式,但结果却很差。 有关详细信息,登录页面位于 assets.xxx.it/login 并且从“/”到“/login”的重定向在应用程序内部处理(通过 React Router)
有什么建议吗?
在使用 certbot
和 Apache 插件创建 SSL 证书时,会创建一个 SSL 配置文件,因此我们想出了一个由我们创建的 vh 80 文件,一个由我们创建的 vh 443 文件我们,以及创建证书时生成的 80 和 443 文件。
如前所述,此文件包含端口 80 和 443 的说明,但是,尽管我们在创建证书时要求重定向,但此 conf
文件中没有这样的说明。所以我们添加了 RedirectMatch
指令并且它起作用了。我们还删除了我们创建的 vh 443 conf 文件,它继续工作。
经过其他搜索我也明白了 Directory
标签中的 RewriteCond
和 RewriteRule
如果您想使用 .htaccess
文件用于更精细控制的 repo 文件夹。