I was working with this config from 2 years without any problem
sudenly I face not found error message from niginx
and its come only when the link has "?"
sample
domain/index.php?a=browse&b=category&id=1
if open the normal link, its working (without "php?")
domain/index.php
domain/[any other php file].php
site config (changed user info)
server {
listen *:80;
server_name domain;
rewrite_log on;
root /home/user/public_html/;
location / {
index index.php index.html index.htm ;
}
location ~*^.+\.jpg|jpeg|gif|css|html|png|js|ico|bmp|zip|rar|txt|pdf|doc)$ {
root /home/user/public_html/;
# expires max;
access_log off;
}
location ~ ^/.+\.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_intercept_errors on;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
}
}
try to use ip change it from
server_name domain;
to
server_name serverip;
and test url
serverip/index.php?a=browse&b=category&id=1
you can check it else with ssh comand
wget localhost/index.php?a=browse&b=category&id=1
if work , check any firewall or any services like cloudflare
Related
If you go to www.example.com/parent/child.php, I want it to rewrite to www.example.com/parent/child
Here is my site's config (without any changes I've made to attempt hiding .php):
server {
listen 80;
server_name example.com;
root /example/root/;
# PHP loaded from here
include /etc/nginx/default.d/php.conf;
location ~* \.(eot|otf|ttc|ttf|woff|woff2)$ {
add_header 'Access-Control-Allow-Origin' '*';
}
location / {
}
Here is the contents of the php.conf file:
index index.php index.html index.htm;
location ~ \.(php|phar|html)(/.*)?$ {
fastcgi_split_path_info ^(.+\.(?:php|phar))(/.*)$;
fastcgi_intercept_errors on;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass php-fpm;
}
I've tried all of the first several results on Google and several that popped up on my search here on stackoverflow including the #extensionless-php suggestion that pops up everywhere.
I haven't tried making any alterations to the php.conf file since it's shared across multiple domains.
Any config changes either do nothing or I just start getting a prompt to download the .php file instead.
Trying to setup 2 applications with same domain, but different paths. I am running php-fpm with nginx and would need every uri starting with "/sub" to be directed to index.php file of /var/www/sub and all others to be directed to /var/www/main.
Latest test can be found below which resolves my locations (as I see in logs), but in error log I get:
open() "/var/www/sub/test/test" failed (2: No such file or directory)
server {
listen 80;
server_name example.com;
access_log /var/log/nginx/default_access.log;
error_log /var/log/nginx/default_error.log debug;
location / {
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log debug;
alias /var/main/public;
index index.php;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
location ^~ /sub {
access_log /var/log/nginx/sub_access.log;
error_log /var/log/nginx/sub_error.log debug;
alias /var/sub/public;
index index.php;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
}
What might be wrong with this configuration or where should I look next?
EDIT: changed alias paths from /var/main to /var/main/public and /var/sub to /var/sub/public
I have PHP 7.2.17 and Nginx 1.15.9 on Ubuntu 19.04.
I have this nginx configuration :
server {
listen 80;
listen [::]:80;
server_name dev.frameworkcms.com;
set $rootpath "/var/www/html/perso/framework-cms test";
error_log "/var/www/html/perso/framework-cms test/logs/error.log" error;
# combined by default
access_log "/var/www/html/perso/framework-cms test/logs/access.log";
root $rootpath/web;
location ~ \.php$ {
fastcgi_intercept_errors on;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index Resources.php;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php7.2-fpm.sock;
}
}
I tried with the port 9000 as well.
i can see the index.html at the project root but not the file web/Resources.php.
I always have a 502 Bad Gateway. Logs are empty.
Edit
I just added a line try_files \$uri /Resources.php; at the beginning of the location block. Now the php file is offered for download...
Edit
Thanks to #Pete Cooper, I have found that the .sock file is not the good one.
Here is the new version of the file :
server {
listen 80;
listen [::]:80;
server_name dev.frameworkcms.com;
set $rootpath "/var/www/html/perso/framework-cms test";
error_log "/var/www/html/perso/framework-cms test/logs/error.log" error;
# combined by default
access_log "/var/www/html/perso/framework-cms test/logs/access.log";
root $rootpath/web;
location ~ \.php$ {
try_files \$uri /Resources.php;
fastcgi_intercept_errors on;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index Resources.php;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
}
I now have a 500 Internal Server Error.
I precise that I work locally.
Try restarting your php-fpm service.
I would like to serve rails, php and static html from the same nginx like this:
example.com - hits php
example.com/app - hits rails
example.com/static - hits static
This situation may be temporary (may be split to multiple servers at some point), so I would like to avoid changes to the code (adding scope or namespace to rails routes - I would like rails to treat "example.com/app" as root).
What should my nginx.conf look like?
I used this page from the passenger docs as reference and tried something like this:
server {
server_name example.com;
listen 80;
root /var/www/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 ~ ^/app(/.*|$) {
alias /var/www/rails/current/public$1;
access_log /var/www/rails/current/log/access.log;
error_log /var/www/rails/current/log/error.log;
passenger_base_uri /app;
passenger_app_root /var/www/rails;
passenger_document_root /var/www/rails/currnet/public;
passenger_enabled on;
passenger_app_env production;
passenger_friendly_error_pages on;
passenger_ruby /usr/local/rvm/gems/ruby-2.1.5#app/wrappers/ruby;
client_max_body_size 4G;
keepalive_timeout 10;
}
}
but I get "not found"
I nearly got it right.
I had the wrong passenger_base_uri.
This is what finally worked for me:
server {
server_name example.com;
listen 80;
root var/www/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 ~^/app(/.*|$) {
alias /var/www/rails/current/public$1;
access_log /var/www/rails/current/log/access.log;
error_log /var/www/rails/current/log/error.log;
passenger_base_uri /app;
passenger_app_root /var/www/rails/current;
passenger_enabled on;
passenger_app_env production;
passenger_friendly_error_pages on;
passenger_ruby /usr/local/rvm/gems/ruby-2.1.5#app/wrappers/ruby;
}
client_max_body_size 4G;
keepalive_timeout 10;
}
I can't figure out how to make the Nginx config file locate my Codeigniter app. Serving PHP on this server is not the problem b/c if I put a php file in my root directory, I can echo "hello world";.
Here's my Nginx config file which is nearly verbatim from this tutorial. Note that I've manipulated many of these parameters and none had an effext so I'm wondering whether I need to look beyond this file to get it to work?:
server {
listen 80;
server_name www.mysite.com mysite.com;
root /var/www;
index index.html index.php index.htm;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
try_files $uri $uri/ /index.php;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
I've been thinking all along this is a simple path issue b/c Codeigniter has a somewhat confusing routing structure but just can't see the problem with my config. Thoughts?
Everything up top matches what I have for a CI project, then this is my location config:
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
Not sure if by removing the wildcard * would help, or getting rid of the split_info param...