HTTPS和Apache Alias上的Wordpress

时间:2015-03-18 17:03:19

标签: php wordpress apache

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

文件夹结构为:

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,因此我手动将数据库中的网址更改为https,仍无法在博客页面上看到任何资源,并且在尝试访问wp-admin时,我获得了重定向循环。

1 个答案:

答案 0 :(得分:0)

安装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>