I don't know why my pages are not eachable without .php extension. Something is wrong ? However it work on another of my website
When I put try_files $uri $uri/ $uri.html $uri.php?$query_string; it's ok for the .php files without extension, but my website create "fakes folders/pages" like mywebsite.lol/category/example - and now it's doesn't reachable (404)
Here is my server{} block configuration.
# Gestion www
server {
# Port
listen 80;
# Hostname
server_name test.mywebsite.lol;
# Logs
access_log /var/log/nginx/test.mywebsite.lol.access.log;
error_log /var/log/nginx/test.mywebsite.lol.error.log;
root /home/mywebsite/www/test;
# Fichier a executer par defaut (en ordre)
index index.html index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# pass the PHP scripts to FastCGI server listening on the php-fpm socket
location ~ \.php$ {
try_files $uri =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;
}
location ~ /\. {
deny all;
}
}
Related
I have my PHP project that handles all the request in index.php file. So, I install nginx on my ubuntu 22.04 and my configuration is:
server {
listen 80;
server_name crm.localtest.me;
root /home/truong/Documents/github/web_projects/crm_system/public;
error_log /home/truong/Documents/github/web_projects/crm_system/public/error_log.html;
location /images {
try_files $uri $uri/ =404;
}
location /js {
try_files $uri $uri/ =404;
}
location /css {
try_files $uri $uri/ =404;
}
location / {
include snippets/fastcgi-php.conf;
include fastcgi_params;
fastcgi_param SCRIPT_NAME index.php;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}
# location ~ \.php$ {
# include snippets/fastcgi-php.conf;
# fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
# }
location ~ /\.ht {
deny all;
}
}
I can browse my home page when access crm.localtest.me but other uri such as crm.localtest.me/auth/login turn to 404 Not Found.
I tried to use
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
but it still not works.
Can anyone done with Codeigniter setup with nginx for hmvc stucture?
Please help me on this, I try to setup up codeigniter HMVC structure on nginx. But fails to many times. Please suggest some wayt to configure it.
I am using php7.0-fpm.
My nginx config file is
server {
listen 80;
root /var/www/html/salsetrack;
index index.html index.htm index.php;
server_name local.sales-track.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
index index.html index.php;
try_files $uri $uri/ #handler;
expires 30d;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
try_files $uri =404;
#Include Nginx’s fastcgi configuration
include /etc/nginx/fastcgi.conf;
#Look for the FastCGI Process Manager at this location
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location #handler {
rewrite / /index.php;
}}
You can refer https://www.nginx.com/resources/wiki/start/topics/recipes/codeigniter/ for nginx configuration for codeigniter.
I'm using nginx and php5-fpm in my ubuntu pc, my site is not loading in browser i have configured everything, but i'm getting 500 internal server error in browser console when i was run my index.php.
This is my code (etc/nginx/sites-available/default)
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html/Inwiter;
index index.php index.htm index.html;
# Make site accessible from http://localhost/
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php;
#try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
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;
}
}
Few days back i also faced this kind of issue (not exactly this issue) that time i was added allow accessToken in my configuration file then it was fine for me.
add_header Access-Control-Allow-Origin *;
As the log you provided, nginx still try to use fastcgi://127.0.0.1:9000 as fastcgi_pass .
Did you restart nginx or reload configuration after modification ?
Besides, please check configuration file in /etc/php5/fpm/pool.d/.
There must be a line with listen = /var/run/php5-fpm.sock.
I recommend you to remove ipv6only=on , and try following sample configuraion:
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_intercept_errors on;
try_files $uri =404;
}
When I am use localhost in url then it redirect to my project but when I use myproject.127.0.0.1.xip.io then It shows Server not found error. Below is my code.
Thanks in advance
server {
listen 127.0.0.1:80;
server_name myproject.127.0.0.1.xip.io;
root /var/www/dev.myproject.com/webroot;
index index.html index.php;
# set expiration of assets to MAX for caching
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
try_files $uri /index.php;
# log_not_found off;
}
location / {
# Check if a file or directory index file exists, else route it to index.php.
try_files $uri $uri/ /index.php;
}
location ~* \.php$ {
try_files $uri /index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_read_timeout 300;
include fastcgi_params;
}
client_max_body_size 10M;
}
Probably the hostname can't be resolved, have you added a
127.0.0.1 myproject.127.0.0.1.xip.io
record to your /etc/hosts file?
I've looks up and down and, while this has been answered dozens of times, I can't get it to work. I'm trying to get apache style multiviews on my PHP site running under nginx. In this case I don't care about all file extensions, just php. So i have my try_files directive:
try_files $uri $uri.php $uri/ $1?$args $1.php?$args
which is all good and dandy, except that when I visit a PHP page without the PHP file extension, the PHP doesn't get rendered and just gets dumped straight to the browser. I see why (PHP is only being used when the location ends in .php, but I've got no idea how to fix it. Here's my config:
server {
listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
root /usr/share/nginx/www;
index index.php index.html index.htm;
server_name inara.thefinn93.com;
location / {
root /usr/share/nginx/www;
try_files $uri $uri.php $uri/ $1?$args $1.php?$args;
}
location ~ ^(.+\.php)$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
In your scenario, the location / is the last processed location setting. Having a try_files on it won't make it past the location ~ ^(.+\.php)$ setting (unless it ends with ".php"), therefore not being forwarded to the fastcgi upstream. You might use a named location for that purpose (locations starting with "#").
Here's an example based on your configuration:
# real .php files only
location ~ ^(.+\.php)$ {
# try_files is not needed here. The files will be checked at "location /"
# try_files $uri =404;
# do not split here -- multiviews will be handled by "location #php"
# fastcgi_split_path_info ^(.+\.php)(/.+)$;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
# also not needed here/with try_files
# fastcgi_index index.php;
include fastcgi_params;
}
# pseudo-multiviews
location #php {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
# search for the split path first
# "$uri/" is not needed since you used the index
try_files $fastcgi_script_name $uri.php =404;
}
# this should also be before "location /"
location ~ /\.ht {
deny all;
}
location / {
root /usr/share/nginx/www;
# if file does not exist, see if the pseudo-multiviews work
try_files $uri #php;
}