nginx is downloading some files instead of executing them - php

For some reason, my nginx installation is running some .php files properly, while doesn't.
I have some files:
upload.php, sig.php, popup.php - executes and works.
asdfsda.php - doesn't work, when I visit it, the file downloads.
(SOLVED by clearing browser cache) visiting my domain - downloads my index.html file with the name "download", when I visit mydoma.in/index.html, I can see my index file properly.
I have no idea what could cause this issue.
I tried:
reinstalling PHP5-FPM
restarting the server
restarting nginx/php5-fpm services
chmod files to 777
Related nginx config part:
root /boot/www;
index index.html index.php;
server_name - my domain here -;
location / {
try_files $uri $uri/ =404;
}
location /upload.php {
include php5.conf;
}
location /asdfsda.php {
include php5.conf;
}
location /popup.php {
include php5.conf;
}
location /sig.php {
include php5.conf;
}
php5.conf:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
This issue started today, I didn't change anything in my config files recently.
It worked fine yesterday.
I'll appreciate any help, thanks!
UPDATE: If I change the name of asdfsda.php file that doesn't execute to something else, it actually does execute. For example, I renamed it to d.php and changed the config entry from asdfsda to d and it executed.
What is wrong?

Why not use this?
location ~ ^/(upload|asdfsda|popup|sig)\.php$ {
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}

Related

NGINX doesn't load css files (wordpress implementation)

I am currently trying to implement a wordpress on a sub-domain using nginx.
I've installed all the dependencies (php 7.2, mariadb, mysql) and configured it all.
When I try to access to the website, here is what I got :
To be more explicit: here's what I did to configure nginx in order to use wordpress:
sudo nano /etc/nginx/conf.d/location.conf
server{
server_name subdomain.domain.fr;
root /home/domain/wordpress/;
location / {
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
include fastcgi_params;
index index.php index.html index.htm;
try_files $uri $uri/ =404;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
My problem is that when I first use a wordpress website, I'm used to see some CSS on the page. When I inspect this page, I can see that the css files are included, but not used. I dont understand why. I think I have a privilege issue or anything else, but it's my first time using nginx with wordpress so I must have done something wrong:
Thanks for your help
I've found a solution that works perfectly:
adding this solved all my problems :
location ~* \.(?:css|js|map|jpe?g|gif|png)$ { }
Thanks for your help

NGINX - No input file specified

Just want to let everyone know before I posted this question I checked
every single thread on stackoverflow about this issue.
The aim:
Run two apps under one domain, first app on the root (/) and second app under the URI (/learn).
http://example.com/ - first app
http://example.com/learn - second app
The problem:
The main app works perfectly, but the learn app is showing a white page with "No input file specified.".
My file structure:
/srv/users/serverpilot/apps/main/public/index.php
/srv/users/serverpilot/apps/learn/public/index.php
My NGINX configuration:
root "/srv/users/serverpilot/apps/main/public";
location ^~ /learn {
root "/srv/users/serverpilot/apps";
try_files $uri /learn/public/index.php?$query_string;
location ~ \.php$ {
add_header X-debug-message $document_root$fastcgi_script_name always;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/srv/users/serverpilot/run/learn.php-fpm.sock;
}
}
location / {
try_files $uri $uri/ /index.php?$args;
location ~ \.php$ {
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/srv/users/serverpilot/run/main.php-fpm.sock;
try_files $uri =404;
}
}
In addition:
I know the fastcgi_pass sockets are working because I've been
running these two apps under different domains but in the same
server in question.
I added the add_header X-debug-message $document_root$fastcgi_script_name" always; to see what the response header would show, and it shows that the
SCRIPT_FILENAME is
/srv/users/serverpilot/apps/learn/public/index.php which exists and is the exact file I am trying to run.
Oh lordy! What a wild hunt!
Okay the reason this configuration wasn't working is because aside from fastcgi_params you can also set php_value[doc_root] which will overwrite your $document_root which is commonly used in the SCRIPT_FILENAME parameter. So check your php.ini files always to make sure php_value[doc_root] is not set when you have apps that are being served from different directories otherwise it just wont pick them up. In the case that you are just serving a single app from a single directory you need not worry.

NGINX not executing php files

First at all I am new here and new to unix. My previous experience was solely with cPanel, Plesk etc. So please forgive me if there are some mistakes in my approach here.
I have a Centos (release 7.3.1611) VPS with Nginx (1.10.2) and PHP (7.0.17).
I followed some guides to get PHP running and followed some answers given here to similar problems as well to no avail.
Here is my configuration:
www.conf:
listen = /run/php-fpm/php-fpm.sock
listen.owner = nginx
listen.group = nginx
user = nginx
group = nginx
I changed permission and ownership on php-fpm.sock.
nginx.conf:
include /etc/nginx/default.d/*.conf;
nginx/default.d/default.conf:
index index.php index.html index.htm;
server_name _;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Finally I have created a info.php file. When executing it I am getting a nginx error: The page you are looking for is temporarily unavailable. Please try again later.
If disabling the nginx error page the browser is asking me if I want to download the file info.php.
Thank you for helping me out!!!
I initially encountered similar issues but fixed by making sure the path to 'include' and 'fastcgi_pass' were valid. You can verify if something is available at these paths by navigating to those directories.
# PHP 7
# cgi.fix_pathinfo=0 in php.ini
# case-sensitive regex
location ~ \.php$ {
include /usr/local/nginx/conf/fastcgi_params;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
try_files $uri $uri/ =404;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
Hope this helps.
Cheers,
Ian

How to make assets work with Symfony3 in subdirectory on Nginx

Based on this question How to install symfony2 app in a subdirectory in nginx
I've created symfony3 application that works in subdirectory called bcms4. I've manged to make php work with PHP-FPM but I have probelms with assets. When I want to GET asset it directs the request to app_dev and shows 404 because obviosly the path does not exist.
My question is how to make assets not to be proccesed by app_dev but downloaded as supposed?
So when I enter
test.localhost/s/asdfad -> it runs symfony
test.localhost/asdf -> it runs other app living in main dir
test.localhost/s/assets/css/test.css -> it will show file in directory /var/www/test.localhost/bcms4/web/assets/css/test.css
My nginx config:
server {
listen 80;
root /var/www/test.localhost;
index index.html index.htm index.php;
# Make site accessible from http://localhost/
server_name test.localhost;
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
}
location ~ ^/s(/.*)$ {
try_files /s/web$1 /web$1 #sf2dev =404;
}
location #sf2dev {
expires off;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/test.localhost/bcms4/web/app_dev.php;
fastcgi_param SCRIPT_NAME /s/app_dev.php;
fastcgi_param REQUEST_URI /s$1;
}
location ~ \.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_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_intercept_errors on;
}
}
After hours of trying I've managed to figure it out with little hack.
This is what I've added to my config file
location ~ ^/s(/.*).\w{1,5}$ {
rewrite ^/s(/.*) /bcms4/web$1 break;
return 404;
}
It'll rewrite files that has prefix /s and extension to directory where they are actually.
Maybe it will help someone. I'll leave question open for a while maybe someone has better solution cause it's seems hacky for me.

Nginx showing 404 instead of php page

I have nginx installed and if I go to uberdrivingparttime.app/ I get the usual "Welcome to nginx!" screen. I put an index.php in the folder with phpinfo(); and when I go to uberdrivingparttime.app/index.php, I get a 404! Here is my server blcok from config. Hopefully someone knows what's up!
server {
listen 80;
server_name www.uberdrivingparttime.com uberdrivingparttime.com;
access_log /srv/www/uberdrivingparttime.com/logs/access.log;
error_log /srv/www/uberdrivingparttime.com/logs/error.log;
location / {
root /srv/www/uberdrivingparttime.com/public_html;
index index.html index.htm index.php;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/uberdrivingparttime.com/public_html$fastcgi_script_name;
}
}
I am a tired, stupid, idiot.
So, everything is good here except for the fact that in /etc/hosts I have .app. The directory where the files are located are .com! Switching the server line to .app fixed everything.
Wow.

Categories