The system is Fedora 25, with Nginx 1.10.2 and PHP 7.0.14 work in CGI Mode.
I using dnf to install phpMyAdmin, the location is /usr/share/phpMyAdmin, so I try to let it work as alias in multi-website.
location /phpmyadmin {
alias /usr/share/phpMyAdmin;
include fastcgi_php.conf;
}
And I add the location into open_basedir.
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/usr/share/phpMyAdmin/:/var/lib/phpMyAdmin/:/etc/phpMyAdmin/:/usr/share/php:/usr/bin/pear:/dev/null:/var/lib/php";
I open the URL and the log show this message:
2016/12/19 17:52:05 [error] 2241#0: *2 FastCGI sent in stderr: "Unable to open primary script: /usr/share/phpMyAdmin/phpmyadmin/index.php (No such file or directory)" while reading response header from upstream, client: 1.1.1.1, server:1.1.1.1 , request: "GET /phpmyadmin/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:"
How to make it correct and work? Thank you!
Update:
I think maybe cause by fastcgi_param, in order to solve the blank page problem in PHP fastcgi, I add 2 line into this file.
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
nginx.conf:
user nginx nginx;
worker_processes 2;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
use epoll;
worker_connections 2048;
multi_accept on;
}
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;
error_log /var/log/nginx/error.log;
include /etc/nginx/mime.types;
default_type application/octet-stream;
geoip_country /usr/share/GeoIP/GeoIP.dat;
charset UTF-8;
sendfile on;
send_timeout 10;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 30;
server_tokens off;
client_header_timeout 10;
client_max_body_size 64M;
client_body_timeout 10;
client_body_buffer_size 256k;
open_file_cache max=102400 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 5;
open_file_cache_errors off;
types_hash_max_size 4096;
reset_timedout_connection on;
fastcgi_buffers 16 32k;
fastcgi_buffer_size 32k;
fastcgi_intercept_errors on;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_min_length 1024;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
fastcgi_php.conf:
location ~ \.php$ {
fastcgi_split_path_info ^(.+?\.php)(/.*)?$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
website.conf:
server {
listen 443 ssl;
server_name test.domain.com;
root /var/www/site1;
index index.html index.php;
access_log /var/log/site1-access.log combined;
error_log /var/log/site1-error.log warn;
ssl_certificate /etc/nginx/ssl/xxx.crt;
ssl_certificate_key /etc/nginx/ssl/xxx.key;
ssl_dhparam /etc/nginx/ssl/dhparams.pem;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
add_header Strict-Transport-Security "max-age=31536000";
add_header X-Content-Type-Options nosniff;
location / {
try_files $uri $uri/ /error.html;
include fastcgi_php.conf;
}
location /phpmyadmin {
alias /usr/share/phpMyAdmin;
include fastcgi_php.conf;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ /\. {
deny all;
}
}
It would work but No such file or directory. Nginx can't find the index.php in /usr/share/phpMyAdmin/phpmyadmin/ because the folder doesn't exists.
You have to edit the alias path of phpmyadmin location (see code snippet how I did). After that go to /usr/share/ path and rename the folder phpMyAdmin to phpmyadmin (lowercase) or use the same notation in Location (e.g. Location /phpMyAdmin)
server {
listen 443 ssl;
server_name test.domain.com;
root /var/www/site1;
index index.html index.php;
# Configure Access and Error Logging
access_log /var/log/site1-access.log combined;
error_log /var/log/site1-error.log warn;
# Configure SSL Certification usage
ssl_certificate /etc/nginx/ssl/xxx.crt;
ssl_certificate_key /etc/nginx/ssl/xxx.key;
ssl_dhparam /etc/nginx/ssl/dhparams.pem;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
# Add Headers for security purposes
add_header Strict-Transport-Security "max-age=31536000";
add_header X-Content-Type-Options nosniff;
# Define some page rules
location / {
try_files $uri $uri/ /error.html;
include fastcgi_php.conf;
}
location /phpmyadmin {
alias /usr/share;
include fastcgi_php.conf;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ /\. {
deny all;
}
Related
Hi I have a website using wordpress on nginx, I have a 404 Not Found error when accessing to it.
https://kilobytes.fr
I'm using a VPS from ScaleWay and my domain is with CloudFlare (Full SSL (Strict)).
Here is the conf of my website:
server {
listen 80;
root /usr/share/nginx/html;
index index.php;
server_name kilobytes.fr www.kilobytes.fr;
return 301 https://$server_name$request_uri; #Redirection
access_log /var/log/nginx/kilobytes.fr.access_log;
error_log /var/log/nginx/kilobytes.fr.error_log;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
try_files $uri $uri/ /index.php?q=$uri&$args;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
satisfy any;
allow all;
}
}
server {
listen 443 ssl http2;
server_name kilobytes.fr wwww.kilobytes.fr;
ssl_protocols TLSv1.2;
ssl_certificate /etc/letsencrypt/live/kilobytes.fr/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/kilobytes.fr/privkey.pem;
## Diffie-Hellman
ssl_ecdh_curve secp384r1;
## Ciphers
ssl_ciphers EECDH+AESGCM:EECDH+AES;
ssl_prefer_server_ciphers on;
# OCSP Stapling
ssl_trusted_certificate /etc/letsencrypt/live/kilobytes.fr/chain.pem;
resolver 80.67.169.12 80.67.169.40 valid=300s;
resolver_timeout 5s;
ssl_stapling on;
ssl_stapling_verify on;
## TLS parameters
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 5m;
ssl_session_tickets off;
## HSTS
add_header Strict-Transport-Security "max-age=15552000; includeSubdomains; preload";
}
and here is the conf of nginx :
user www-data;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
gzip on;
client_max_body_size 100M;
server_tokens off;
include /etc/nginx/sites-enabled/*;
}
My root folder for wordpress is : /usr/share/nginx/html/
I tried a lot of things and nothing worked.. Thanks !
I have spent hours trying to figure this out and read many articles, all of which don't solve the issue.
I keep getting:
*2 connect() failed (111: Connection refused) while connecting to upstream client: 81.xxx.xxx.xxx, server: localhost, request:"GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "52.xxx.xxx.xxx"
I am using Ubuntu 14.4 on an Amazon EC2 micro instance.
nginx.conf:
user www-data;
worker_processes 1;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
client_body_timeout 12;
client_header_timeout 12;
keepalive_timeout 15;
send_timeout 10;
gzip on;
gzip_proxied any;
gzip_types text/plain text/xml text/css application/x-javascript;
gzip_vary on;
gzip_min_length 1100;
gzip_buffers 4 32k;
gzip_disable “MSIE [1-6]\.(?!.*SV1)”;
open_file_cache max=5000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
server {
listen 80 default_server;
listen 443 ssl;
server_name localhost;
index index.php index.html;
ssl_certificate /etc/ssl/cacert.pem;
ssl_certificate_key /etc/ssl/privkey.pem;
ssl_session_cache shared:SSL:20m;
ssl_session_timeout 180m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;
ssl_dhparam /etc/ssl/dhparam.pem;
add_header Strict-Transport-Security "max-age=31536000" always;
pagespeed on;
pagespeed RewriteLevel CoreFilters;
pagespeed FileCachePath "/var/cache/pagespeed/";
pagespeed FileCacheSizeKb 102400;
pagespeed FileCacheCleanIntervalMs 3600000;
pagespeed FileCacheInodeLimit 500000;
#charset koi8-r;
#access_log logs/host.access.log main;
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
location / {
root html;
}
#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 html;
}
# 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_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
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;
#}
}
client_body_buffer_size 10K;
client_header_buffer_size 1k;
client_max_body_size 8m;
large_client_header_buffers 2 1k;
}
PHP5 FPM www.conf:
[www]
...
user = www-data
group = www-data
listen = /var/run/php5-fpm.sock
#listen = 127.0.0.1:9000
#listen = /tmp/php5-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
...
What is causing this problem?
i'm having a problem with my application made with php and the Laravel Framework.
The issue is with file uploads/downloads.
When i submit files to the server it stores them good, but when i try to download an uploaded file larger than 100KB it just downloads part of it making it corrupt.
Tried a lot of options by adjusting php.ini settings, nginx settings and still can't solve it.
Here is my current configuration for nginx:
nginx.conf
user developer;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Now here is my nginx site config:
server {
listen 8002 default_server;
server_name localhost 172.20.74.229 cadeco.dev;
root /var/www/current/cadeco/public;
index index.php index.html index.htm;
access_log /var/log/nginx/cadeco.dev-access.log;
error_log /var/log/nginx/cadeco.dev-error.log error;
charset utf-8;
include h5bp/basic.conf;
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; }
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
sendfile off;
client_max_body_size 100m;
location ~ ^/index\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Then here are the related settings of php.ini from (/etc/php5/fpm/php.ini):
max_execution_time = 30
max_input_time = 60
memory_limit = 512M
upload_max_filesize = 50M
max_file_uploads = 20
And finally here is my php script that does the file download:
public function downloadFile($file)
{
$filePath = storage_path('app/uploads/').$file;
if (Storage::exists($file))
{
return response()->download($filePath);
}
Flash::error('File does not exists!');
return redirect()->back();
}
Thanks for any help in advance! :D
i figured it out!.
I checked the error log for this nginx site and found this error:
*10 open() "/var/lib/nginx/fastcgi/4/00/0000000004" failed (13: Permission denied) while reading upstream, client: 172.20.73.101, server: localhost, request: XXXXX
This error ocurred because some time ago we changed the user to www-data to start services like the php-fpm, but i forgot to change it for nginx.
Changed the user to www-data and now everything works as it should!
Thanks!
So I am setting up my first Linode (sort of new to managing everything myself). However, I have the following problem. The browser downloads the php file instead of executing it and MS Internet Explorer shows the file's content instead of downloading it.
I've read through a lot of content/answers about this problem but nothing seems works so I'd appreciate your help.
Important to note is that the website "crashes" only when I add the following line to the Virtual Host file
location ~* .(ico|jpg|webp|jpeg|gif|css|png|js|ico|bmp|zip|woff)$ {
expires 365d;
}
Here are the two files in full
NGINX.CONF
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 10s;
types_hash_max_size 2048;
# server_tokens off;
server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
# ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
# ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log debug;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
and the sites-available/default file
server {
listen 80 default_server;
listen [::]:80 default_server;
root /www/bloggingwithdani.com;
index index.html index.php index.htm;
server_name localhost;
# pagespeed On;
# pagespeed FileCachePath "/var/cache/ngx_pagespeed/";
# pagespeed EnableFilters combine_css,combine_javascript;
location / {
try_files $uri $uri/ /index.php?$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~* .(ico|jpg|webp|jpeg|gif|png|ico|bmp|zip|woff|css|js|)$ {
expires 365d;
}
location ~ /\. {
deny all;
}
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
location ~ [^/]\.php(/|$) {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
if (!-f $document_root$fastcgi_script_name) {
return 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;
}
}
your php location block looks wrong to me. here's my location block for php
location ~ \.(php)$ {
try_files $uri = 404;
location ~ \..*/.*\.php$ {return 404;}
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_keep_conn on;
fastcgi_pass unix:/var/run/php5-fpm.sock;
# fastcgi_pass 127.0.0.1:9000; #passing directly to the socket
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
also, your static file caching is wrong, and has an erroneous wild card parameter. remove the last | and optionally add some extra configuration options to further optimize delivery of static content.
location ~* .(ico|jpg|webp|jpeg|gif|png|ico|bmp|zip|woff|css|js)$ {
expires max;
add_header Vary Accept-Encoding;
access_log off;
}
I have a basic symfony2 app, when I try to reach the host I get a download instead of the execution of the PHP code.
This is the vhost configuration:
server {
listen 80;
server_name sandobox.dev www.sandbox.dev;
root /var/www/sandbox/web;
rewrite ^/app\.php/?(.*)$ /$1 permanent;
try_files $uri #rewriteapp;
location #rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
# Deny all . files
location ~ /\. {
deny all;
}
location ~ ^/(app|app_dev)\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index app.php;
send_timeout 1800;
fastcgi_read_timeout 1800;
#fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_pass 127.0.0.1:9001;
}
# Statics
location /(bundles|media) {
access_log off;
expires 30d;
# Font files
#if ($filename ~* ^.*?\.(eot)|(ttf)|(woff)$){
# add_header Access-Control-Allow-Origin *;
#}
try_files $uri #rewriteapp;
}
}
This is my nginx.conf file
user nginx;
worker_processes 4;
worker_cpu_affinity 01 10;
worker_rlimit_nofile 1024;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
# max_clients = worker_processes * worker_connections
worker_connections 1024;
}
# Global environment variables
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush off;
keepalive_timeout 65;
keepalive_requests 100;
send_timeout 60;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
# Logging of trivial open() errors resulting in 404 to error log
log_not_found off;
# Send back the version in the error pages?
server_tokens off;
# Files to serve when directories are requested
index index.php index.htm index.htm;
# Automatic directory indexing
autoindex off;
# Defaults to on, but it's a problem for trailing slash redirections
server_name_in_redirect off;
# Increase the maximum length of a virtual host entry
server_names_hash_bucket_size 64;
# Compression
gzip on;
gzip_disable "msie6";
gzip_min_length 0;
gzip_types text/plain;
# Include separately managed configuration file(s)
include /etc/nginx/conf.d/*.conf;
}
~
~
~
~
Thanks in advance for any hint