Nginx unable to access parts of the website - php

Si I'm trying to run Invision Forums on nginx but it can't seem to access the uploads folder for some reason. It's most likely my configuration that's wrong but I'm not really sure since this is the first time I'm working with nginx.
Here's my configuration file:
worker_processes 1;
user www-data;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
server {
listen 80;
listen [::]:80;
server_name localhost;
root /var/www/forums;
index index.php;
charset utf-8;
client_max_body_size 100M;
fastcgi_read_timeout 1800;
location / {
try_files $uri /index.php;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}

Related

How to open a phar.php file under nginx?

I'am running ddev under macos with apple silicon m1.
I'am trying to open a phar (Contao-Manager.phar.php) file in the browser but got a 404.
webroot is correctly set, because its is possible to open a test.php in same webroot in the browser.
Here Is My nginx-conf:
server {
listen 80 default_server;
listen 443 ssl default_server;
root /var/www/html/web;
ssl_certificate /etc/ssl/certs/master.crt;
ssl_certificate_key /etc/ssl/certs/master.key;
include /etc/nginx/monitoring.conf;
index index.php index.htm index.html;
sendfile off;
error_log /dev/stdout info;
access_log /var/log/nginx/access.log;
location / {
absolute_redirect off;
try_files $uri $uri/ /index.php?$query_string;
}
location #rewrite {
rewrite ^ /index.php;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/run/php-fpm.sock;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_intercept_errors off;
fastcgi_read_timeout 10m;
fastcgi_param SERVER_NAME $host;
fastcgi_param HTTPS $fcgi_https;
}
location ~* /\.(?!well-known\/) {
deny all;
}
location ~* (?:\.(?:bak|conf|dist|fla|in[ci]|log|psd|sh|sql|sw[op])|~)$ {
deny all;
}
include /etc/nginx/common.d/*.conf;
include /mnt/ddev_config/nginx/*.conf;
}
Try to change your default location to this (didn't check if works):
location / {
absolute_redirect off;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
try_files $fastcgi_script_name $uri $uri/ /index.php?$query_string;
}
And check your access.log and error.log if it's not working.
The problem is somewhere between fastcgi_split_path_info and your location order (which location actually handles *.php request first).
It is also possible that your regular expression in fastcgi_split_path_info doesn't match Contao-Manager.phar.php (file has 2 extensions).

php nginx config request for this address in a way that will never complete only php not wordpress

I am the beginner for nginx
I am tryingt to do
www.mywebsite.com/index.php to show in the url like www.mywebsite.com/
and
www.mywebsite.com/index.php/user/login to show in the url like www.mywebsite.com/user/login
and I got the error as show in the picture.
Here is my nginx.config
#user nobody;
worker_processes 4;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name www.wcp6288.com;
root /var/www/wangou;
index index.html index.htmi index.php;
#charset koi8-r;
#access_log logs/host.access.log main;
if ($request_uri ~* "^(.*/)index\.php$") {
return 301 $1;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
# Remove from everywhere index.php
if ($request_uri ~* "^(.*/)index\.php(/?)(.*)") {
return 301 $1$3;
}
}
# Remove trailing slash.
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 permanent;
}
# Clean Double Slashes
if ($request_uri ~* "\/\/") {
rewrite ^/(.*) /$1 permanent;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/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$ {
root /var/www/wangou/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include fastcgi.conf;
try_files $uri $uri/ =404;
}
}
}
Thanks you for your helps.
Should you remove
try_files $uri $uri/ =404;
In block:
location ~ \.php$ {
root /var/www/wangou/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include fastcgi.conf;
try_files $uri $uri/ =404;
}
Here is my config and it's worked.
server {
listen 80;
listen 443 ssl http2;
server_name test.dev;
root "/var/www/html/test/";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
access_log off;
error_log /var/log/nginx/test.dev-error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
}

Multiple PHP based server blocks in nginx - 404 Error

I am pretty new in Nginx and I have a problem with it. I have two wordpress websites and I want to start them with Nginx on a Centos Linux. What I have done is:
creating sites-available and sites-enabled in the /etc/nginx/
Put my website configuration files (.conf) into sites-available
I created symbolic links for them using ln -s
My configuration files are as follow:
nginx.conf
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
# include /etc/nginx/conf.d/*.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
index index.html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
include /etc/nginx/sites-enabled/*.conf;
server_names_hash_bucket_size 64;
}
mydomain1.com.conf
server {
listen 80;
server_name mydomain1.com www.mydomain1.com;
location / {
root /var/www/html/;
index index.php;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
mydomain2.com.conf
server {
listen 80;
server_name mydomain2.com www.mydomain2.com;
location / {
try_files $uri $uri/ =404;
root /var/www/aramis;
index index.php;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
/etc/php-fm.d/www.conf
[www]
listen = /var/run/php-fpm/php-fpm.sock
listen.allowed_clients = 127.0.0.1
listen.owner = nobody
listen.group = nobody
;listen.mode = 0660
user = nginx
group = nginx
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
I also tried to find php-fpm.sock but I was not successful.
What I get when try to see my websites from browser is 404 Error.
You have no root directive for your PHP location block. If it is the same root for all files (both static and dynamic) then move the root directive to the server block and allow the same value to be inherited by both location blocks.
server {
...
root /var/www/aramis;
index index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri =404;
...
}
}
See this document for more.
Your need resolve the redundance
mydomain1.com.conf
server {
listen 80;
root /var/www/html/; # Set as global
server_name mydomain1.com www.mydomain1.com;
index index.php # Set index as global
location / {
# index index.php; #Remove this line
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
myworkingfile.conf
server {
listen 80;
server_name crm.coderic.net;
root /var/www/atrk/crm.atrk.com.co/public;
index index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

Ubuntu 16.04, nginx, phpmyadmin - 502 Bad Gateway

I am using this setting for nginx (default file):
server {
listen 30425;
# Don't want to log accesses.
#access_log /dev/null main;
access_log /var/log/nginx/php.acces_log main;
error_log /var/log/nginx/php.error_log info;
root /usr/share/phpmyadmin;
index index.php index.html index.htm;
error_page 401 403 404 /404.php;
location ~ .*.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SERVER_NAME $http_host;
fastcgi_ignore_client_abort on;
}
}
When I try to access 30425, I am getting 502 Bad Gateway. All other setting are default one (PHP 7).
I had to replace this fastcgi_pass 127.0.0.1:9000;
to fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
and then it worked perfectly.
Full code.
server{
listen 80;
index index.html index.htm index.php;
server_name 127.0.0.1;
root /usr/share/phpmyadmin;
location / {
#try_files $uri $uri/ = 404;
autoindex on;
}
location ~\.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+);
try_files $uri $uri/ =404;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_na$
fastcgi_param SERVER_NAME $http_host;
fastcgi_ignore_client_abort on;
}
}

nginx rewrite rules codeigniter

i am using Winginx for using nginx php and mysql on windows.
i want run and config CodeIgniter 2.
Winginx structure:
d:\winginx|
nginx.exe
php5\php.exe
mysql\mysqld.exe
\home\localhost\public_html\codeigniter
base this (http://wiki.nginx.org/Codeigniter)
and this (http://www.farinspace.com/codeigniter-nginx-rewrite-rules/)
and this (Nginx rewrite rule for CodeIgniter)
i try coonfig ci but i just see codeigniter 404 page (no nginx 404 page)
my ci config.php is
$config['base_url'] = "";
$config['index_page'] = "";
$config['uri_protocol'] = "AUTO";
..
nginx.config is
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid temp/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
client_max_body_size 55m;
#gzip on;
scgi_temp_path temp/uwsgi_temp 1 2;
uwsgi_temp_path temp/uwsgi_temp 1 2;
fastcgi_connect_timeout 1;
include codeigniter.conf;
}
i include codeigniter.conf in nginx.conf
codeigniter.conf is:
server {
listen 80;
server_name localhost;
root home/localhost/public_html/codeigniter:
autoindex on;
index index.php;
location / {
try_files $uri $uri/ /index.php?/$request_uri;
location = /index.php{
fastcgi_pass localhost:9000;
#fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
}
location ~ \.php$ {
return 444;
}
}
i try 3 different coonfig ci but i just see codeigniter 404 page (no nginx 404 page).
http://localhost/codeigniter/welcome/index -> CI 404 page!
http://localhost/codeigniter/welcome -> CI 404 page!
http://localhost/codeigniter -> CI 404 page!
i guest the problem is created by the php file location in codeigniter.conf
please help me to config it !
I'd try this
server {
listen 80;
server_name localhost;
root home/localhost/public_html/codeigniter;
autoindex on;
index index.php;
location / {
try_files $uri $uri/ /index.php;
}
location = /index.php {
fastcgi_pass localhost:9000;
#fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
location ~ \.php$ {
return 444;
}
}
Here's what I use for a production CI install
server
{
listen 80 default_server;
server_name www.site.com;
root /var/www;
index index.php;
# canonicalize codeigniter url end points
location ~ ^/index.php/(.*[^/])$ { return 301 $scheme://$host/$1/$is_args$args; }
location ~ ^/index.php/(.*)/$ { return 301 $scheme://$host/$1/$is_args$args; }
location / {
# Check if a file or directory index file exists, else route it to index.php.
try_files $uri $uri/ /index.php;
}
location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
I got it working the following way...
server {
listen 127.0.0.1:80;
server_name xxxx www.xxxx;
root home/xxxx/public_html;
autoindex on;
index index.php;
location / {
try_files $uri $uri/ /index.php?/$request_uri;
location ~ \.php$ {
if (!-e $document_root$document_uri){
return 404;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
location ~ \.php$ {
return 444;
}
}

Categories