Codiginter 3 : 404 for all pages except assest - php

I am trying to deploy my Codeigniter 3 HMVC website in nginx (AWS). I have tried all the solutions I found in SO but none of them worked. It is been 6 hours now. Please someone help m e out here.
I have installed nginx and tested a "Hello World" in a PHP file and it works fine.
(All the static files in assets/ folder are served in the browser. Only the routing seems to cause the issue for other urls)
This is the configs in my /etc/nginx/sites-enabled/blahblah.lk
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/blah/public/;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name blahblah.lk;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php;
}
location ~* ~/(assets|files|robots\.txt){}
# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
#location /RequestDenied {
# proxy_pass http://127.0.0.1:8080;
#}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/share/nginx/html;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

If nginx is running properly, it might be a codeigniter setup issue.
Check the rewrite rules and make sure your controllers have uppercase-first filenames, while the controller subfolders are all-lowercase. That kept me from going for hours.

Related

my_ip/phpmyadmin shows 404 Not Found on Nginx and after one tutorial instead loading my website it downloads a file

Trying to install phpMyAdmin on Nginx. Following all tutorials carefully, but when head my website my_IP/phpmyadmin I get 404 Not Found anyway.
And when I was loading my website by typing my IP address I got my website. But after following this tutorial instead of showing my website my browser downloads file "download". I deletted that code piece from tutorial, restarted Nginx, but browser still downloads a "download" file instead of heading my website. And when I type my_IP/phpmyadmin I still get 404 Not Found.
How I can get my settings back and run phpMyAdmin on my Nginx server?
Here is /etc/nginx/sites-available/default settings:
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
}
UPD:
Updated my PHP8.1, uncommented some important code pieces and added location /phpmyadmin code piece from that tutorial.
Looks like page is loading correctly, but my_IP/phpmyadmin still loads 404 Not Found.
Finally figured it out myself.
Actually in directory /etc/nginx/sites-available/ I already had two files, default and my_website.com. That piece of code I put into default. But now I moved this code to my_website.com file and it worked:
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
Thank you for attention!

Can't run Laravel app on digitalocean using ngnix

My Laravel app is returning 404 on every route.
This is the address: http://67.205.191.11/, when I try for example http://67.205.191.11/classes, 404 not found is returned.
my nginx default config file looks as below:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/venture-backend/public/;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name 67.205.191.11;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
#location /RequestDenied {
# proxy_pass http://127.0.0.1:8080;
#}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/share/nginx/html;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
Anyone knows why my routes are not working?

How to enable two wbesite to work on Nginx Digital ocean server

So while following this tutorial to implement two website on my NginX server.
Lin to the Website
I created two folder as follow
sudo nano /etc/nginx/sites-available/ideconnect.com
my file look like this
server {
listen 80;
listen [::]:80;
root /var/www/ideconnect.com/html;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name ide-portal.com www.ide-portal.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Then the other website
sudo nano /etc/nginx/sites-available/iclock.com
server {
listen 80 ;
listen [::]:80;
root /var/www/iclock.com/html;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name iclock.in www.iclock.in;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Also I have created the SYMLINKS properly
sudo ln -s /etc/nginx/sites-available/ideconnect.com /etc/nginx/sites-enabled/ideconnect.com
sudo ln -s /etc/nginx/sites-available/iclock.com /etc/nginx/sites-enabled/iclock.com
After this when I got to my ip address I can only see the default Nginx Page also now the info.php configuration page is also not visible.
Any help would be appreciated
Thanks
There are two things you can check to begin with:
Did you restart nginx?
Are you sure your nginx configuration is set up to include .com files? I think the default is to include all .conf files. You can check that in your nginx configuration file and then adapt that or modify the extension of your symlinks.

Nginx extensionless PHP rewrite not working

I have been trying to rewrite my php pages so that they display without their extensions in the browser. For example, a link on my server at www.example.com loads a page called about-us.php and in the browser, the user would see www.example.com/about-us.
I have been trying to follow these tutorials to try and get this to work, but sadly they are not working.
Tweak Talk Link
Stack Overflow Link
Here is my nginx sites-available/default file content.
# Server Block
server {
# Listening Ports
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
# Root Location Initialization
root /home/zach/Documents/Workspaces/www;
index index.php index.html index.htm;
# Server Name
server_name localhost;
# Root Location
location / {
try_files $uri $uri/ #extensionless-php;
}
# Error pages
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/zach/Documents/Workspaces/www;
}
# PHP Handling
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# Extensionless PHP
location #extensionless-php {
rewrite ^(.*)$ $1.php last;
}
}
All of my links to php pages still display the .php extension in the browser, does anyone have any solutions to my problem?
Add the following line to the exact spot where you think it'd form a loop! :-)
if ($request_uri ~ ^/([^?]*)\.php($|\?)) { return 302 /$1?$args; }
More info here: nginx remove .php and .html file extension

Codeigniter + Nginx must render 404 page provided by framework

So, I have next problem. This is my nginx config
server {
disable_symlinks off;
listen 80;
server_name g9tv.loc;
charset utf-8;
#access_log logs/host.access.log main;
location / {
root /home/dejmos/www/g9tv;
index index.html index.htm index.php;
try_files $uri $uri/ /index.php;
}
error_page 404 /index.php;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/dejmos/www/g9tv;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_intercept_errors on;
root /home/dejmos/www/g9tv;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/dejmos/www/g9tv$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
When I go to page that not exists on server I got 404 page provided by nginx, but I need to get 404 page provided by codeigniter show_404() function.
Problem resolved. It caused by subfolder. I place Codeigniter to root folder and all ok now.

Categories