【问题标题】:Wordpress on HTTPS and Apache AliasHTTPS 和 Apache 别名上的 Wordpress
【发布时间】:2015-03-18 17:03:19
【问题描述】:

我正在尝试设置我们的博客,但无法破解正确的配置...

文件夹结构为:

var/www/domain
| - website
| - webapp
| - blog

Apache 配置:

<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin admin@example.com

# -------------------------------------
# ------        Web Stuff        ------
# -------------------------------------

# Website
DocumentRoot /var/www/example.com/production/website/code/wwwroot
<Directory "/var/www/example.com/production/website/code/wwwroot">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Order allow,deny
    Allow from all
</Directory>

# Webapp
Alias /pages /var/www/example.com/production/webapp
<Directory "/var/www/example.com/production/webapp">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Order allow,deny
    Allow from all
</Directory>

# Blog
Alias /blog /var/www/example.com/production/blog
<Directory "/var/www/example.com/production/blog">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Order allow,deny
    Allow from all
</Directory>

DirectoryIndex index.php index.html

CustomLog ${APACHE_LOG_DIR}/domain_production_access.log combined
ErrorLog ${APACHE_LOG_DIR}/domain_production_error.log
LogLevel warn

# -------------------------------------
# -------------------------------------

# Catch any requests for example.com and redirect them to www.example.com
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) https://www.example.com/$1 [NC,R=301,L]

# Catch any http requests (except for status check and those that originated from
# this server) and redirect them to https
RewriteEngine On
RewriteCond %{HTTP_HOST} !=localhost
RewriteCond %{HTTP:X-Forwarded-Proto} !https

RewriteRule !/api/aws/check https://%{SERVER_NAME}%{REQUEST_URI} [NC,R=301,L]

# Django web service - all URLs beginning with /api
WSGIDaemonProcess www.example.com processes=8 threads=1 display-name=%{GROUP}

 ... FOLLOWED BY A LOT OF SETTINGS FOR API ...

 <LocationMatch "\.(jpg|css|gif|pdf|ico)$">
    SetHandler None
</LocationMatch>

# Zip output
AddOutputFilterByType DEFLATE text/css text/html application/x-javascript application/javascript application/json
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

我已经在博客目录中安装了 WordPress 并连接到数据库。但是当我尝试打开 https://www.example.com/blog 时,我看到了内容但没有样式(所有资产都来自非 https 地址)。

我无法访问 wp-admin,所以我手动将数据库中的 url 更改为 https,但在博客页面上仍然看不到任何资产,并且在尝试访问 wp-admin 时出现重定向循环。

【问题讨论】:

    标签: php wordpress apache


    【解决方案1】:

    安装https plugin 解决了它。有两个不同的问题:

    1) 无限循环 2) 从 http 提供的资产

    插件解决了这两个问题,第一个问题是通过将 .htaccess 添加到根目录(我尝试了百万次,但显然我在重写规则中犯了一些错误)。

    但这并不能解决资产问题(我知道,我尝试过/测试过)。这意味着这个 pugin 也必须在 php 中做一些魔术,按照我的逻辑,这在 wordpress 本身中是一个相当大的问题......

    作为参考,.htaccess 的外观如下:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /blog/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-06
      • 2018-10-06
      • 2021-05-24
      • 1970-01-01
      • 1970-01-01
      • 2021-04-14
      • 2015-08-07
      相关资源
      最近更新 更多