我是否需要在 LAMP 中为 HTTPS 网站配置端口 80?

Lin*_*eak 3 ssl lamp lets-encrypt

我有一个 LAMP 网络服务器,上面有https://sslhosting.cz/域。

首先,我附上一个通用的 Let's Encrypt 配置文件,我根据需要对其进行了更改:

/etc/letsencrypt/options-ssl-apache.conf

# Baseline setting to Include for all Let's Encrypt SSL sites


SSLEngine               on


# Intermediate configuration, tweak to your needs
SSLProtocol             all -SSLv2 -SSLv3
SSLCipherSuite          ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDH$
SSLHonorCipherOrder     on
SSLCompression          off
SSLOptions              +StrictRequire


# Add vhost name to log entries:
LogFormat               "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" vhost_combined
LogFormat               "%v %h %l %u %t \"%r\" %>s %b" vhost_common


#CustomLog              /var/log/apache2/access.log vhost_combined
#LogLevel               warn
#ErrorLog               /var/log/apache2/error.log


# Always ensure Cookies have "Secure" set (JAH 2012/1)
#Header                 edit Set-Cookie (?i)^(.*)(;\s*secure)??((\s*;)?(.*)) "$1; Secure$3$4"


# HSTS = HTTP Strict Transport Security
Header                  always set Strict-Transport-Security "max-age=63072000; includeSubdomains; preload" env=HTTPS
Header                  always set X-Frame-Options DENY


# OCSP Stapling
SSLCACertificateFile    /etc/apache2/certificates/letsencrypt-crosssigned-stapling.pem
SSLUseStapling          on
Run Code Online (Sandbox Code Playgroud)

我是否需要在 Virtualhost 中为 HTTPS 网站配置端口 80?请注意,我希望将 HTTP 重定向到 HTTPS。

遵循具体的网站配置:

/etc/apache2/sites-available/sslhosting.cz-le-ssl.conf

<VirtualHost *:80>

  ServerName             sslhosting.cz
  ServerAlias            www.sslhosting.cz

  RewriteEngine          on

  RewriteCond            %{HTTPS} !on
  RewriteRule            ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]

  RewriteCond           %{HTTP_HOST} ^www\.sslhosting\.cz
  RewriteRule           ^(.*)$ https://sslhosting.cz/$1 [R=301,L]

</VirtualHost>


<IfModule mod_ssl.c>

        <VirtualHost *:443>

                ServerAdmin     admin@vlastimilburian.cz

                ServerName      sslhosting.cz
                ServerAlias     www.sslhosting.cz

                DocumentRoot    /var/www/sslhosting.cz/public_html
                ErrorLog        ${APACHE_LOG_DIR}/error.log
                CustomLog       ${APACHE_LOG_DIR}/access.log combined

                SSLCertificateFile      /etc/letsencrypt/live/sslhosting.cz/fullchain.pem
                SSLCertificateKeyFile   /etc/letsencrypt/live/sslhosting.cz/privkey.pem

                Include         /etc/letsencrypt/options-ssl-apache.conf

        </VirtualHost>

        SSLStaplingCache        shmcb:/tmp/stapling_cache(128000)

</IfModule>
Run Code Online (Sandbox Code Playgroud)

现在,问题:

我是否需要在 LAMP 中为 HTTPS 网站配置端口 80?

dmo*_*ati 11

题为“我是否需要在 LAMP 中为 HTTPS 网站配置端口 80?”的答案。是不是,你别。您可以在您想要的任何端口上运行 LAMP 堆栈。常见的选择包括 80,443 (SSL/TLS)、8080、8000 等。

在问题中,您添加了一条皱纹,从而稍微改变了答案。

“请注意,我希望将 HTTP 重定向到 HTTPS。”

如果您希望您的网络服务器执行该重定向,并且假设您使用标准的 http 端口 80/tcp,那么答案变为 yes。您需要配置端口 80 才能完成重定向。

为了完整起见,我可以想到其他一些方法来获得不依赖于网络服务器上的端口 80 的工作配置。

一种是在前面使用负载平衡器来处理重定向。

二是使用iptables重定向端口。请注意,在您的情况下,这不能完全处理 SSL/TLS 要求。

  • 此外,如果您要进行 HTTP -&gt; HTTPS 重定向,您还应该查看 HSTS,并实现它所需的标头。最近的浏览器支持该规范,并且在一次 HTTP 连接后,它们将始终尝试以 HTTPS 联系您的站点。 (4认同)
  • @KoenvanderRijt ...如果服务器首先不侦听端口 80,浏览器应该如何获取包含重定向到端口 443 的 http 数据包?;-) (3认同)