I have Amazon ec2 server running nginx + php-fpm-5.6
It opens php pages correctly when there are no errors, but if any kind of error occurs (php error or exception) it always displays the same page (/test.php is the requested url):
Forbidden
You don't have permission to access /test.php on this server.
Additionally, a 403 Forbidden error was encountered while trying to
use an ErrorDocument to handle the request.
I tried changing php "display_errors" option.
When I enable it all scripts begin to show 403 page. In php error log I see a warning message that I should define default timezone. When I define it with
date_default_timezone_set(...); in my scripts 403 error goes and appears only when a script has some mistake or if I write throw new Exception(); for example.
How can I bring back normal error messages with details of an error and place in file where it has occured?
Upd. My nginx configuration:
server {
listen 80 default_server;
server_name localhost;
root /var/www/html;
index index.php index.html;
client_max_body_size 200m;
access_log /var/log/nginx/admin.xuno.com.au.access.log;
error_log /var/log/nginx/admin.xuno.com.au.error.log;
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;
proxy_read_timeout 120;
}
}
Main nginx.conf
user dev-user;
worker_processes auto;
error_log /var/log/nginx/error.log;
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;
include /etc/nginx/conf.d/*.conf;
}
Related
I have nginx running as confirmed by loading an html page.
The difficulty is running a .php page in same location, however this giving a 404.
fpm is shown to be installed okay using php-fpm -t
Therefore I am very sure its in .conf or a serverblock.
My goal is to set everything using serverblocks (aka VirtualHosts) as so much easier to manage differing projects so have attempted to strip nginx.conf to a minimal:
#user nobody;
worker_processes 1;
error_log /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;
#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;
#gzip on;
include /usr/local/etc/nginx/sites-enabled/*;
}
and the serverblock
server {
listen 80;
server_name localhost;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root /var/www;
index index.php index.html index.htm;
try_files $uri /index.php?&query_string;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_read_timeout 60;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
}
index.php fails simply with a message 'File not found' though not in the usual nginx format - just those words.
I had assumed this would be simple on a Linux based OS. It seems Apple have messed with it too much to make it viable.
I have expertise in this and have a Ubuntu based script which makes everything ready to go on this Linux flavour - apparently Apple no longer support developers.
Oh well lets see how long it takes to install a VirtualBox solution that I can edit on OSX.
This is an answer per se pending details from other people answering as I have had this working before - I just wanted a non proxy solution and was prepared to find a few days finding it. Alas Apple prevent it.
I'm new to all of this, but can't keep my newly spun micro ec2 server up and running (running wordpress). The PHP-FPM log only has this with logging set to debug.
[17-Oct-2016 15:46:38] NOTICE: configuration file /etc/php5/fpm/php-fpm.conf test is successful
My nginx log is continuously filling with errors trying to connect to php5-fpm.sock (hundreds of entries per minute even though there is no one else accessing the site).
2016/10/17 16:32:16 [error] 26389#0: *7298 connect() to unix:/var/run/php5-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 191.96.249.80, server: mysiteredacted.com, request: "POST /xmlrpc.php HTTP/1.0", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "removed"
After restarting nginx and PHP-FPM the site works for a few minutes before throwing 502 Bad Gateway errors until I restart them both again.
I don't know where to begin with this. Here is my nginx config file:
user nginx;
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;
port_in_redirect off;
gzip on;
gzip_types text/css text/xml text/javascript application/x-javascript;
gzip_vary on;
include /etc/nginx/conf.d/*.conf;
}
Which also include this file in the /conf.d folder:
server {
## Your website name goes here.
server_name mysiteredacted.com www.mysiteredacted.com;
## Your only path reference.
root /var/www/;
listen 80;
## This should be in your http block and if it is, it's not needed here.
index index.html index.htm index.php;
include conf.d/drop;
location / {
# This is cool because no php is touched for static content
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
fastcgi_buffers 8 256k;
fastcgi_buffer_size 128k;
fastcgi_intercept_errors on;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# fastcgi_pass unix:/dev/shm/php-fpm-www.sock;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location ~* \.(css|js|png|jpg|jpeg|gif|ico)$ {
expires 1d;
}
}
The second file has this line:
fastcgi_pass unix:/var/run/php5-fpm.sock;
If that file does not exist it will throw this error.
Check this previous question: How to find my php-fpm.sock?
After hours of searching I finally figured it out.. Turns out it's some sort of brute force attack on /xmlrpc.php as indicated by the thousands of requests of "POST /xmlrpc.php HTTP/1.0".
It's a common WordPress attack. Thanks all.
EDIT: I have noticed the first time you visit it to goes fast, and it also goes fast if you close the browser tab and re-visit it, but if you simply reload or visit it when you have a tab of it open it goes slow, it is really confusing.
today I come with a problem about PHP CGI, I am brand new to nginx and have just installed it, when I noticed I need to start PHP cgi also with it because with IIS it started it for me. so I start php with batch file below but the problem is... slow php files, they load really slowly even if its just html in them.
#ECHO off
echo Starting PHP, please wait!
C:\nginx\php7\php-cgi.exe -b 127.0.0.1:9054 -c C:\nginx\php7\php.ini
ping 127.0.0.1 -n 1>NUL
ping 127.0.0.1 >NUL
EXIT
Am I doing anything wrong with my batch file or nginx config below? (I have 2 configs) the example.com one is the website with a .php file and the nginx (localhost) just has index.html
localhost loads super fast but example.com one loads really slow because of php.
nginx.conf
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;
#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;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root C:\Users\Administrator\Dropbox\websites\local_website;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
if (!-e $document_root$document_uri){return 404;}
fastcgi_pass localhost:9054;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
include vhosts/*.conf;
}
example.com.conf
server {
listen ***.***.**.***:80;
server_name example.com www.example.com;
root C:\Users\Administrator\Dropbox\websites\php_website;
index index.php index.html;
log_not_found off;
charset utf-8;
#access_log logs/example.com-access.log main;
location ~ /\. {allow all;}
location / {
rewrite ^/(|/)$ /index.php?url=$1;
rewrite ^/([a-zA-Z0-9_-]+)(|/)$ /index.php?url=$1;
rewrite ^/(.*)\.htm$ /$1.php;
}
location = /favicon.ico {
}
location = /robots.txt {
}
location ~ \.php$ {
if (!-e $document_root$document_uri){return 404;}
fastcgi_pass localhost:9054;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
I had the exactly same problem as you do. try changing your fastcgi_pass.
from this
fastcgi_pass localhost:9054
to this
fastcgi_pass 127.0.0.1:9054
I use laravel 5.1 and nginx/1.8 it's the first time for me with Nginx Server
When i try to access laravel app home page the route working well
get('/', function () {
return view('welcome');
});
But when i try to access any other page
get('/home', function () {
return 'Home Page';
// Or Blade Page
//return view('home');
});
Nginx return
My settings file on /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
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;
include /etc/nginx/mime.types;
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 localhost;
#root /usr/share/nginx/html;
root /var/www/nginx/html;
index index.php index.html index.htm;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
Update
the last result of /var/log/nginx/error.log
#3 /var/www/nginx/html/laravel/vendor/laravel/framework/src/Illuminate
/Foundation/Exceptions/Handler.php(49):
Monolog\Logger->error(Object(Symfo
2016/01/11 22:59:38 [error] 22510#0: *31 directory index of "/var/www/nginx/html/laravel/" is forbidden, client: 127.0.0.1, server: _, request: "GET /laravel/ HTTP/1.1", host: "localhost"
Note:html/laravel -> laravel is the app name
Any Suggestions ?
Root needs to point to the public folder of your laravel installation. If you've installed laravel into /var/www/nginx/html, then it should be:
root /var/www/nginx/html/public
Iv'e setup an Nginx php server on a linux REHL machine.
When accessing html files all goes well, but trying to access php file, the file is downloaded instead of being executed.
This is my nginx.conf:
user nginx;
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;
include /etc/nginx/conf.d/*.conf;
}
...and this is the server block:
server {
listen 80;
server_name {mywebsitename};
#access_log logs/host.access.log main;
location / {
root /usr/share/nginx/html/{mywebsitename}/;
}
location /ngx_status_2462 {
stub_status on;
access_log off;
allow all;
}
location ~ \.php$ {
# fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/{mywebsitename}$fastcgi_script_name;
include fastcgi_params;
}
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;
}
}
It might be because of the mimetype you're sending:
default_type application/octet-stream;
See: http://mimeapplication.net/octet-stream
I just had this exact same problem. I was using Ubuntu 12.04 and Linux Mint 14 so different OS but likely to have the same issues.
A couple of issues may happening. Firstly, you need to have php5-fpm installed (FastCGI Process Manager). I was trying to run it with my standard version of PHP but it was not working - http://www.php.net/manual/en/install.fpm.php
I also had Apache installed, and even if it weren't running it must have had some conflict because once I uninstalled Apache I was able to execute the PHP files.
I would also look at this line
fastcgi_pass 127.0.0.1:9000;
And consider changing it to
fastcgi_pass unix:/var/run/php5-fpm.sock;
Here is a detailed guide to installation of Nginx and PHP5-FPM for RHEL (and other OS's)
http://www.if-not-true-then-false.com/2011/install-nginx-php-fpm-on-fedora-centos-red-hat-rhel/
You need to change the user to nginx instead of apache in this file a/etc/php-fpm.d/www.conf
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
; RPM: apache Choosed to be able to access some dir as httpd
;user = apache
user = nginx
; RPM: Keep a group allowed to write in log dir.
;group = apache
group = nginx
and of course restart service php-fpm restart and service nginx restart
Comment out default_type application/octet-stream;