AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-446349

mlclm's questions

Martin Hope
mlclm
Asked: 2020-11-30 06:25:18 +0800 CST

HSTS 和 Wordpress 重定向到 www 和非 www 和 https - 避免多次重定向?

  • 2

我正在尝试在我的 Wordpress 网站上实施 HSTS(HTTP 严格传输安全),但没有取得任何成功。首先,我设法将我的网站从非 www 重定向到 www ,包括 https:// ,但我在https://hstspreload.org/上收到消息,它应该首先重定向到 www。

我试图使用 VirtualHosts 配置文件,没有运气。所以我做了一些谷歌搜索,发现这个链接看起来像是 htaccess 的解决方案,但我仍然遇到问题。如果有人知道如何通过 VirtualHost / Apache 配置文件来实现这一点,那就太好了。

错误:HTTP 首先重定向到 www http://inter.net (HTTP) 应在添加 www 子域之前立即重定向到https://inter.net(HTTPS)。现在,第一个重定向是 to https://www.inter.net/。需要额外的重定向以确保任何支持 HSTS 的浏览器都会记录顶级域的 HSTS 条目,而不仅仅是子域。

我的 htaccess 如下:

# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

#### This is what I added : From https://www.danielmorell.com/guides/htaccess-seo/redirects/https-www-and-trailing-slash 
#### Force HTTPS://WWW and remove trailing / from files ####
## Turn on rewrite engine
RewriteEngine on

# Remove trailing slash from non-filepath urls
RewriteCond %{REQUEST_URI} /(.+)/$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ https://www.inter.net/%1 [R=301,L]

# Include trailing slash on directory 
RewriteCond %{REQUEST_URI} !(.+)/$
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+)$ https://www.inter.net/$1/ [R=301,L]

# Force HTTPS and WWW 
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [OR,NC]
RewriteCond %{https} off  
RewriteRule ^(.*)$ https://www.inter.net/$1 [R=301,L]

# Yoast SEO - XML Sitemap Rewrite Fix
RewriteEngine On
RewriteBase /
RewriteRule ^sitemap_index.xml$ /index.php?sitemap=1 [L]
RewriteRule ^locations.kml$ /index.php?sitemap=wpseo_local_kml [L]
RewriteRule ^geo_sitemap.xml$ /index.php?sitemap=geo [L]
RewriteRule ^([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 [L]
RewriteRule ^([a-z]+)?-?sitemap.xsl$ /index.php?yoast-sitemap-xsl=$1 [L]
# END Yoast SEO - XML Sitemap Rewrite Fix

ps - inter.net 网址仅作为示例。

编辑 - 我已经编辑了我的 example.com.conf 文件,以在下面的答案中添加我的 MrWhite 的额外规则 - 这看起来很准确。运行命令 apachectl configtestSyntaw 后正常。运行service apache2 reload更改以使更改生效,并让所有浏览器都说页面未正确重定向:(**ERR_TOO_MANY_REDIRECTS**每次为每个不同的浏览器清除缓存)。

我只将 htaccess 恢复为原始的 Wordpress 和 Yoast SEO 规则。

我当前在 apache 上为此 VirtualHost 的配置文件可能有问题,但 apachectl configtest 没有语法错误:https ://paste.ofcode.org/vr25hFkPEt2vYjpM5sAUxK

我尝试使用 Firefox Developer 模块(F12)来查看是否可以理解任何其他信息,问题似乎是 301 重定向循环https://www.example.com

编辑2:感谢@MrWhite,我明白ServerAlias细节是不必要的,是循环的原因。问题解决了,从中吸取了教训。

apache-2.2 .htaccess redirect mod-rewrite hsts
  • 1 个回答
  • 708 Views
Martin Hope
mlclm
Asked: 2018-11-19 01:40:04 +0800 CST

如何重置被重定向页面的 max-age 缓存控制(302)

  • 1

几个小时前,我在 htaccess 中使用以下代码将主页重定向到维护页面:

维护重定向

RewriteCond %{REQUEST_URI} !/maintenance/index.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|js|css) [NC]
RewriteCond %{REMOTE_ADDR} !^92\.95\.110\.92
RewriteRule .* /maintenance/index.html [R=302,L]

然后我将代码注释掉以便能够再次显示页面,但是在将访问权限更改回之前重定向仍然发生。我也重新启动了服务器。然后我检查了一个在线工具的标题,这就是发生的事情:

 Sun, 18 Nov 2018 07:57:58 GMT
Server:
    Apache
Location:
    http://www.website.com/maintenance/index.html
Cache-Control:
    max-age=172800
Expires:
    Tue, 20 Nov 2018 07:57:58 GMT
Content-Length:
    231
Content-Type:
    text/html; charset=iso-8859-1
Via:
    1.1 varnish (Varnish/6.1), 1.1 varnish (Varnish/6.1)
X-Cache-Hits:
    31
X-Cache:
    HIT
Age:
    5602
Connection:
    keep-alive

Redirecting to: http://www.website.com/maintenance/index.html

看起来 302 重定向以某种方式缓存到 2018 年 11 月 20 日?

我试图在页面上添加以下代码,重新启动服务器。没有发生重定向,但页面完全空白:

 <?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>

我可以重置这个“临时”302 重定向以尽快停止吗?并完全删除它?我可以访问 linux shell。非常感谢您的帮助。

linux
  • 1 个回答
  • 608 Views
Martin Hope
mlclm
Asked: 2018-02-04 01:20:37 +0800 CST

如何在 VirtualHost 配置文件中指定重发 SSL 证书的替换文件?

  • 1

环境:Linux 4.4.0-77-generic,Ubuntu 16.04.2 LTS with Apache 2 (Apache/2.4.18 (Ubuntu))

情况如下:我有一个 SSL 证书,用于没有www 的域。基本上我认为www.domain-name.com并被domain-name.com认为是 1 个域,并且 SSL 证书适用于两个 URL,但我了解到它仅适用于domain-name.com(因此在 url 中没有www)。

我购买了 3 个额外的域(基本上是相同的域,但这次是 'www' 在域 url's 中)。

发生的事情是 Comodo 给我发了一个 zip 文件,这次不是 2 个文件,而是 4 个文件。我想知道在 VirtualHost 配置文件(apache2、ubuntu 16.04)中指定这些新文件的正确方法是什么?

昨天和今天早上,我花了很多时间试图使 SSL 证书正常工作,最终还是成功了……但仅适用于非 www url。所以我可能快到了……只需要保护www域。

这是一个快速图形,显示了我遇到的问题和疑问。这是我第一次这样做,所以它可能会让人感到困惑,尤其是在这个案例上花费了很多小时之后:)

快速描述我的问题

linux
  • 1 个回答
  • 68 Views
Martin Hope
mlclm
Asked: 2018-02-03 11:35:09 +0800 CST

VirtualHosts 和 SSL,与 apache 的正确设置混淆

  • 0

我已经红色了很多教程,有些没有任何日期,有些可能已经过时,有些在一些细节上不清楚......现在我很困惑。整天都在这上面。

我正在使用带有一些虚拟主机的 ubuntu 16.04 / apache2。

我得到了一个 ssl 证书,下载了文件并上传了它们。有一个捆绑文件和一个 .crt 文件。密钥文件是在该过程的早期生成的。

我猜我的第一个问题是关于虚拟主机的配置文件。一些教程说要使用文件:default-ssl.conf,里面是:/etc/apache2/sites-available,并将其用作基础。

另一个教程说在主 domain-example.com.conf 文件中包含有关证书的所有详细信息。

那么,一个域是否应该有 2 个文件,文件 main-domain.com.conf 用于 :80 端口,另一个文件是 default-ssl.conf 用于 :443 端口?

我的另一个问题是关于一些东西的语法和正确名称。首先,那部分:

<IfModule mod_ssl.c>
    <VirtualHost _default_:443>

是否VirtualHost _default_需要这样命名,VirtualHost _default_?还是我必须更换一些东西?这_default_部分看起来很奇怪。

我的另一个问题是关于在配置文件中使用的正确名称:SSLCACertificateFile或SSLCertificateChainFile

还遵循了托管公司的教程,其中说虚拟主机的配置文件应该有服务器的 IP,所以它看起来像(注意<VirtualHost 155.131.133.211:80>部分):

<VirtualHost 155.131.133.211:80>
        ServerAdmin [email protected]
        ServerName sitexample.com
        ServerAlias www.sitexample.com
        DocumentRoot /var/www/html/sitexample.com/

真的是这样吗?因为在尝试了一天不同的事情之后,在某些时候,sitexample.com 不再指向具有正确路径 /var/www/html/sitexample.com/ 的正确网站,而是指向具有“索引”的页面作为标题,它看起来像主 IP 服务器页面。

linux
  • 1 个回答
  • 325 Views
Martin Hope
mlclm
Asked: 2018-02-03 04:57:36 +0800 CST

在 apache2 服务器上正确实现 SSL 证书?

  • 0

情况:

我从 namecheap/Comodo 购买了一个多域(它包括 3 个域:主域,例如:maindomain.com和另外两个域:sitea.com和siteb.com)。

到目前为止,我想看看是否只能首先为主站点正确设置证书。

在线阅读不同的教程后,我认为为了在 3 个网站上成功使用 SSL 证书,可能需要编辑的文件列表如下:

/etc/apache2/sites-available/maindomain.com.conf
/etc/apache2/apache2.conf 
/etc/apache2/ports.conf

已下载证书的文件列表:

115155984.ca-bundle
115155984.crt

(请注意文件 115155984.ca-bundle 没有任何扩展名)

现在,看起来该站点maindomain.com似乎指向服务器 IP 地址( 155.133.130.203 )。我不确定为什么。我已maindomain.com.conf在目录中的文件内容下方发布sites-available。有几点可能会改变证书的正确实施。

我的问题如下:

  • 1) 我有一个没有 crt 扩展名的 ca-bundle 文件:我必须手动添加 crt 扩展名吗?
  • 2) 我下载的文件没有得到任何 pem 文件:PEM 文件会在某个时候生成吗?
  • 3) 我的 /etc/hosts 文件是否正确?我添加了多行以确保至少有一个可以解决问题。我敢肯定它包含很多不必要的行。我把它贴在下面。
  • 4)我的证书文件不是名为 maindomain.com.crt 而是有一个随机数,这有关系吗?
  • 5)我在这个过程中早些时候生成的密钥文件没有域扩展名 .com ,它的命名如下: maindomain.key 如果我记得它是与之前的 csr 文件同时生成的(做了那个步骤前一段时间)

/etc/apache2/sites-available/maindomain.com.conf 文件

以下是 sites-available 目录中 maindomain.com.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
            DocumentRoot /var/www/html

            # 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
    </VirtualHost>

    # vim: syntax=apache ts=4 sw=4 sts=4 sr noet

    <IfModule mod_ssl.c>
        <VirtualHost 155.133.130.203:443>
                ServerAdmin [email protected]
                ServerName maindomain.com
                ServerAlias www.maindomain.com
                DocumentRoot /var/www/html/maindomain.com/
                ErrorLog ${APACHE_LOG_DIR}/error.log
                CustomLog ${APACHE_LOG_DIR}/access.log combined

                SSLEngine on

                SSLCertificateFile /etc/ssl/certs/115155984.crt

                SSLCertificateKeyFile /etc/ssl/private/maindomain.key

                SSLCACertificateFile /etc/ssl/certs/115155984.ca-bundle.crt

                SSLVerifyClient None

                <Directory />
                          Options FollowSymLinks
                          AllowOverride None
                </Directory>
                <Directory /var/www/html/maindomain.com/>
                          Options Indexes FollowSymLinks MultiViews
                          AllowOverride All
                          Order allow,deny
                          allow from all
                </Directory>
        </VirtualHost>
    </IfModule>

/etc/host 文件中的不必要信息

这是我在 /etc/ 中的主机文件的内容。在 PHPMailer 可以从站点发送电子邮件之前,我必须尝试一些不同的事情,因此很可能有很多不必要的行。

    127.0.0.1       localhost
    ::1             localhost ip6-localhost ip6-loopback
    ff02::1         ip6-allnodes
    ff02::2         ip6-allrouters

    155.133.130.203 servername01.maindomain.com
    155.133.130.203 servername01.maindomain.com server01.sitea.com
    127.0.0.1 server01 server01.sitea.com sitea.com
    127.0.0.1 server01 server01.maindomain.com maindomain.com
    155.133.130.203 test.maindomain.com
    155.133.130.203 maindomain.com
    155.133.130.203 sitea.com
linux
  • 1 个回答
  • 40 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve