I'm having what seems to be a common problem deploying a codeigniter web app to an Amazon AWS EC2 instance and configuring it for SSL/TLS.
The app is running on an Amazon Linux 2 AMI (HVM) instance.
The web app works fine under HTTP i.e. the basic URL will load the index.php with the default route. The codeigniter routes all call the controller functions fine and load the respective views and any functions on the page that use AJAX to call a controller function all work fine.
When trying with HTTPS the basic URL will load the index.php with the default route, however when adding routes to the end of the URL I encounter a 404 not found error.
Not Found
The requested URL was not found on this server.
The same is true with any functions on the page that use AJAX to call a controller function:
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
I've been following the guide here: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/SSL-on-amazon-linux-ami.html and have:
- Enabled mod_ssl
- Used Route 53 to set up the DNS records for my domain
- Have a CA-signed certificate (90 day certificate from ZeroSSL)
- Placed the certificate in /etc/pki/tls/certs
- Placed the key in /etc/pki/tls/private
- Updated SSLCertificateFile and SSLCertificateKeyFile in ssl.conf accordingly
Loading the index page under HTTPS (https://www.mysite.co.uk) in a browser works fine. All of the elements are loaded (css and images) and I see the closed padlock symbol in the address bar. Clicking on it states the connection is secure and the certificate is valid, so it appears the configuration there is OK.
In addition:
- I've updated the vhost with an entry for port 443:
<VirtualHost *:80>
ServerAdmin [email protected]
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 [email protected]
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>
The .htaccess file is as follows:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$0 [L]
</IfModule>
I've tried the config.php file with base_url settings of:
$config['base_url'] = 'https://www.mysite.co.uk';
as opposed to the original
$config['base_url'] = 'http://www.mysite.co.uk';
The values for index_page and uri_protocol are:
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
Controller names have initial characters in uppercase, and as things are working with HTTP in a linux environment I can discount case sensitivity being an issue. Likewise as the routes work under HTTP I don't think it is an issue with the routes.php file:
$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';
I've tried many permutations for the .htaccess file.
I'm sure there is something I'm missing somewhere but have been going around in circles for he last few days to no avail.
Is there anything obvious I've missed somewhere along the line? Any assistance greatly appreciated.
CodePudding user response:
I deployed a fresh CI4 with a custom domain on a fresh beanstalk instance. I used amazon certificate. Never used SSH. All done through web interface.
Only changes I did on codeigniter
- copied
.htaccessandindex.phpfrom/publicto root folder - altered
$pathsConfiginindex.phpto point project subfolder - altered
$baseURLinConfig\App.phpand addedhttps://
This should run with no problem.
What I suspect is ssl is not configured properly and it points to another virtual host or the default apache directory.
Try creating a regular file in the root folder /test.php and try to access it. If you still get 404 error then your virtual host configuration is broken.
CodePudding user response:
Thanks @Ergec, it does look like a virtual host issue. It can't be picking up the vhost.conf file correctly.
Adding the virtual host section for port 443 to then end of httpd.conf and restarting the service has done the trick.
