【发布时间】:2021-12-24 09:51:16
【问题描述】:
在将 codeigniter Web 应用程序部署到 Amazon AWS EC2 实例并将其配置为使用 SSL/TLS 时,我遇到了一个似乎很常见的问题。
应用在 Amazon Linux 2 AMI (HVM) 实例上运行。
Web 应用程序在 HTTP 下运行良好,即基本 URL 将使用默认路由加载 index.php。 codeigniter 路由都可以正常调用控制器函数并加载相应的视图,并且页面上使用 AJAX 调用控制器函数的任何函数都可以正常工作。
当尝试使用 HTTPS 时,基本 URL 将使用默认路由加载 index.php,但是当将路由添加到 URL 末尾时,我遇到了 404 not found 错误。
Not Found
The requested URL was not found on this server.
页面上任何使用 AJAX 调用控制器函数的函数也是如此:
Request URL: https://www.mysite.co.uk/Home/test_fn
Request Method: POST
Status Code: 404 Not Found
Remote Address: xx.xxx.xxx.xx:443
Referrer Policy: strict-origin-when-cross-origin
我一直在关注这里的指南:https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/SSL-on-amazon-linux-ami.html 并拥有:
- 启用 mod_ssl
- 使用 Route 53 为我的域设置 DNS 记录
- 拥有 CA 签名证书(来自 ZeroSSL 的 90 天证书)
- 将证书放在 /etc/pki/tls/certs 中
- 将密钥放在 /etc/pki/tls/private 中
- 相应地更新了 ssl.conf 中的 SSLCertificateFile 和 SSLCertificateKeyFile
在浏览器中加载 HTTPS (https://www.mysite.co.uk) 下的索引页可以正常工作。所有元素都已加载(css 和图像),我在地址栏中看到关闭的挂锁符号。点击它表明连接是安全的并且证书是有效的,所以那里的配置看起来是好的。
另外:
- 我已经用端口 443 的条目更新了虚拟主机:
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/var/www/html/myApp"
ServerName https://www.mysite.co.uk/
<Directory "/var/www/html/myApp">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/var/www/html/myApp"
SSLEngine on
SSLCertificateFile "/etc/pki/tls/certs/certificate.crt"
SSLCertificateKeyFile "/etc/pki/tls/private/private.key"
ServerName https://www.mysite.co.uk/
<Directory "/var/www/html/myApp">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
.htaccess 文件如下:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$0 [L]
</IfModule>
我已尝试使用 base_url 设置的 config.php 文件:
$config['base_url'] = 'https://www.mysite.co.uk';
相对于原来的
$config['base_url'] = 'http://www.mysite.co.uk';
index_page 和 uri_protocol 的值是:
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
控制器名称的初始字符为大写,并且由于在 linux 环境中使用 HTTP,我可以忽略区分大小写的问题。同样,由于路由在 HTTP 下工作,我认为 routes.php 文件不是问题:
$route['default_controller'] = 'Home';
$route['home'] = 'Home';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['companies'] = 'Company_c/view_companies';
$route['users'] = 'User_c/view_users';
$route['layers'] = 'Layer_c/view_layers';
我为 .htaccess 文件尝试了许多排列方式。
我确定我在某处遗漏了一些东西,但他过去几天一直在兜圈子,但无济于事。
我在这条线上的某个地方有什么明显的遗漏吗?非常感谢任何帮助。
【问题讨论】:
标签: php amazon-web-services codeigniter ssl