在AWS with Load Balancer上将CodeIgniter与Wordpress配合使用,将https与https配合使用,在AWS上,Wordpress永久链接不起作用 [英] CodeIgniter with Wordpress, https with http, on AWS with Load Balancer, Wordpress permalinks not working

查看:68
本文介绍了在AWS with Load Balancer上将CodeIgniter与Wordpress配合使用,将https与https配合使用,在AWS上,Wordpress永久链接不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下设置。具有负载均衡器的Elastic Beanstalk环境。安装在根目录中的Web应用程序正在使用CodeIgniter。 Wordpress安装在根目录下的/ blog子目录中。 CodeIgniter应用程序需要https,但wordpress必须是http。负载均衡器配置为侦听https和http,负载均衡器后面的实例为http。



我要管理的第一个配置是根目录中的.ebextensions文件。 。该文件与应用程序一起部署,以设置一个.conf来将所有http通信重定向到https EXCEPT / blog。该文件如下所示:

 文件:
/etc/httpd/conf.d/ssl_rewrite.conf:
模式: 000644
所有者:root
组:root
内容:|
上的
RewriteEngine<如果 -n’%{HTTP:X-Forwarded-Proto}'&&%{HTTP:X-Forwarded-Proto}!=‘https’>
RewriteCond%{REQUEST_URI}!^ / blog /
RewriteRule(。*)https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
< / If>

配置的下一步是根目录中的.htaccess文件。这控制CI请求。看起来像这样:

 < FilesMatch \。(ttf | otf | eot | woff | woff2 | svg)$ > 
< IfModule mod_headers.c>
标头集Access-Control-Allow-Origin *
< / IfModule>
< / FilesMatch>

RewriteEngine on
RewriteBase /
RewriteCond $ 1!^(index\.php | uploads | blog | assets | robots.txt)
RewriteRule ^( 。*)$ /index.php/$1 [L]
选项-索引

最后在包含Wordpress的/ blog目录中,我有这个.htaccess

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

CI应用正常运行,并且将HTTP请求发送到https正确。 / blog根目录本身(即主页,例如 http://example.com/blog )也可以。甚至/ blog /子目录,例如 http://example.com/blog/ wp-admin / options-general.php 工作正常。无效的是永久链接,例如 http://example.com/blog/my-article(大概是因为它们不是真实文件)。如果我更改了永久链接设置以删除永久链接并允许发布网址看起来像这样 http:// example .com / blog /?p = 123 也可以。只有永久链接不起作用。



另一个问题(应该很明显)是,如果有人尝试直接使用https访问博客,则会收到混合内容警告和断开的链接。因此,我还需要将 https://example.com/blog/ *重定向回http。 p>

我确信此设置过于复杂,可以删除两个.htaccess文件并将所有设置都放在.ebextensions配置文件中,但是我不确定该怎么做。我一直在拼凑几个解决方案,例如 = https://stackoverflow.com/questions/3307025/force-https-on-certain-urls-and-force-http-for-all-others>几天,每种解决方案都会产生另一个问题



对于任何人也建议Wordpress也应使用https,我并不反对,但是我已经走了一个多星期,没有任何好处。该解决方案使我能够维护非ssl测试和开发环境,这些环境将正确部署到AWS,而不会造成混乱的插件,生产中发生更改的文件(我无法轻易将其移植回测试和开发环境)以及其他其他https / wordpress问题。最简单的解决方案似乎正在运行Wordpress http。我也愿意使用另一个CMS来取代Wordpress。最重要的是,我只想让博客在AWS的CI下生活在https / http下,在一起玩耍并易于部署。



开发和测试,一切正常。开发人员和测试人员之间唯一的显着区别是.ebextensions文件和https重定向。



我们将提供任何帮助。

解决方案

观看此视频:
AWS解决方案
,您需要使用正确的标头,以免发生这种情况,尤其是在您的负载均衡器未在实例与负载均衡器


I have the following setup. An Elastic Beanstalk Environment with a Load balancer. The web application, installed in the root, is using CodeIgniter. Wordpress is installed in the subdirectory /blog off the root. The CodeIgniter application requires https, but wordpress needs to be http. The load balancer is configured to listen on https and http, the instances behind the load balancer are http.

My first configuration to manage this is a .ebextensions file in the root. This file is deployed with the application to set a .conf to redirect all http traffic to https EXCEPT /blog. That file looks like this

files:
    "/etc/httpd/conf.d/ssl_rewrite.conf":
        mode: "000644"
        owner: root
        group: root
        content: |
            RewriteEngine On
            <If "-n '%{HTTP:X-Forwarded-Proto}' && %{HTTP:X-Forwarded-Proto} != 'https'">
            RewriteCond %{REQUEST_URI} !^/blog/
            RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
            </If>

The next step in the configuration is an .htaccess file in the root. This controls the CI requests. It looks like this:

<FilesMatch "\.(ttf|otf|eot|woff|woff2|svg)$">
  <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
  </IfModule>
</FilesMatch>

RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|uploads|blog|assets|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Options -Indexes

Finally in the /blog directory containing Wordpress I have this .htaccess

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

The CI app works fine, and http requests are sent to https correctly. The /blog root directory itself (i.e. the 'home page' such as http://example.com/blog) also works fine. Even the /blog/subdirectories such as http://example.com/blog/wp-admin/options-general.php work fine. What does not work are permalinks such as http://example.com/blog/my-article (presumably because they are not real files). If I change the permalinks setting to remove the permalinks and allow post urls to look like this http://example.com/blog/?p=123 that also works. Only permalinks do not work.

An additional problem (which should be obvious) is that if anyone tries to access the blog with https directly, they will get a mixed content warning and broken links. So I also need to redirect https://example.com/blog/* back to http.

I am sure this setup is over complicated, and I could remove both .htaccess files and place all my settings in the .ebextensions config file however I am not sure how to do that. I have been piecing together several solutions such as this and this for days and each solution creates another problem.

For anyone going to suggest that Wordpress should be https as well, I am not opposed to that, however I have been down that road for over a week with no good solution that allows me to maintain non-ssl test and development environments that will deploy to AWS properly without messy plugins, files that change in production which I cannot easily port back to test and dev, and host of other https/wordpress problems. The simplest solution seems to be running Wordpress http. I'm also open to another CMS to replace Wordpress. Bottom line is I just want a blog to live under CI on AWS, in https/http, play nice together, and deploy easily.

It should also be noted that in dev and test, everything works fine. The only significant difference between dev and test is the .ebextensions file and the https redirect.

Any help is appreciated.

解决方案

Take a look on this video: AWS solution you need to use the correct header so that does not happend, especially if your load balancer is not using secure connections between the instance and the load balancer

这篇关于在AWS with Load Balancer上将CodeIgniter与Wordpress配合使用,将https与https配合使用,在AWS上,Wordpress永久链接不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆