PHP5-FPM keeps crashing on new micro instance, log is blank - php

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.

Related

Time-out 504 Gateway Time-out nginx in wordpress-php-fpm

I want to setup WordPress PHP-fpm in Kubernetes, so I already setup that but there is some problem that currently I am facing with Nginx proxy, so when I am trying to install the woo-commerce plugin then it gives the error of
Installation failed: 504 Gateway Time-out 504 Gateway Time-out nginx padding to disable MSIE and Chrome friendly error page -> < ! - padding to disable MSIE and Chrome friendly error page ->
I don't know what's going wrong on proxy I already set the max value for proxy_read_timeout 100. but then also it will not work. I tried so many proxy time-out values but it didn't work, so here is my Nginx proxy config
wordpress.conf
server {
listen 80;
server_name localhost;
root /var/www/html;
index index.php;
#access_log /var/log/nginx/hakase-access.log;
#error_log /var/log/nginx/hakase-error.log;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass wordpress:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_cache phpcache;
fastcgi_cache_valid 200 301 302 60m;
fastcgi_cache_min_uses 1;
fastcgi_cache_lock on;
add_header X-FastCGI-Cache $upstream_cache_status;
fastcgi_cache_use_stale error timeout updating invalid_header http_500 http_503;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
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;
fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=phpcache:100m max_size=10g inactive=60m use_temp_path=off;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
The one working for me
location ~ \.php$ {
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
fastcgi_connect_timeout 300s;
fastcgi_send_timeout 60;
fastcgi_read_timeout 60;
}
You must be running the two containers inside the single pod you can debug the logs of ingress and nginx of WordPress to check more details.
you can use this github as reference : https://github.com/harsh4870/Kubernetes-wordpress-php-fpm-nginx
Also, check the blog to understand more : https://medium.com/#harsh.manvar111/kubernetes-wordpress-php-fpm-nginx-73cb4f9aef02

PHP opcache causes function failure

What is the situation?
2 websites: A and B ( laravel5.2 )
A want to using B's javascript file
B is using opcache
B using git update codes and post-hook request specified URL reset opcache
website A codes:
<script src="https://B/controller/getJsFunction"></script>
website B codes:
public function getJsFunction()
{
header('Content-Type:application/javascript');
header('Cache-Control: max-age=0, must-revalidate');
//mix('/js/visitor.js') will get visitor.js and auto add the current version
echo file_get_contents(rtrim(public_path(), '/') . mix('/js/visitor.js'));
}
What I want?
website A get the website B's javascript file content
B can upgrade the javascript file version number any time, visitor.v1.js => visitor.v2.js
What happened?
B sustain return 502 HTTP status code after a period of successful operation,
When B Modified any code trigger opcache_reset(), even just add comments, the bug will fix a while.
What I have?
nginx log
2018/05/06 03:56:17 [error] 12747#0: *28155344 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: xxxxxxx, server: xxxxxxx.com, request: "GET /stateless/visitor/js HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "xxxxxx.com", referrer: "https://xxxxxx"
git post-receive
cd /path/to/site-B/project
unset GIT_DIR
git pull origin master && curl https://site-B.com/cache.php
cache.php
<?php
opcache_reset();
nginx.conf
user nginx nginx;
worker_processes auto;
error_log /var/log/nginx/error.log error;
pid /var/run/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
http {
include /etc/nginx/black.ip;
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"';
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 600;
fastcgi_read_timeout 600;
types_hash_max_size 2048;
client_max_body_size 20m;
gzip on;
index index.html index.htm index.php;
server {
listen 80 default;
server_name _;
return 403;
}
server {
listen 80;
listen 443;
server_name site-b.com;
root /path/to/site-b.com/public;
ssl on;
ssl_certificate /path/to/site-b.com.crt;
ssl_certificate_key /path/to/site-b.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
if ($scheme = http ) {
rewrite ^(.*)$ https://$host$1 permanent;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~* \.(jpg|jpeg|png|gif|js|css|ico|eot|svg|ttf|woff|woff2)$
{
expires max;
add_header Cache-Control public;
add_header Pragma public;
add_header Vary Accept-Encoding;
}
location ~* \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
What help I need?
How to REALLY fix the bug?
Or what other methods should I use?
Or why reset_opcache() can fix the bug? Or why opcache causes this bug?
Since this is an online project, I temporarily modified it to that site A first request site B to get the current version of the javascript file, and then insert a script tag and set src url from first step response

Nginx php files loading slow

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

Nginx shows 403 page on all php errors

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;
}

Laravel 4: 502 Bad Gateway with Nginx only in one view

I have a strange error in my server with nginx because I was working on this project for many months and everything is working fine except just for one view/page I added because is showing me 502 Bad Gateway but I don't why.
I already deleted the whole html of that view just to print a simple text but is the same
I already removed the whole functionality from the controller just to render the view but is the same
I already changed the route and the name of the controller but is the same
I have tried many things but the problem still persisting and in the log of my server block is showing only this:
Nginx server block error log
2015/08/05 08:25:42 [error] 2423#0: *885 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 187.189.190.62, server: stage.mywebsite.com, request: "GET /business/user/site.com/edit HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "stage.mywebsite.com", referrer: "http://stage.mywebsite.com/business"
php-fpm error log
[05-Aug-2015 08:25:42] WARNING: [pool www] child 6825 exited on signal 11 (SIGSEGV) after 28731.872473 seconds from start
[05-Aug-2015 08:25:42] NOTICE: [pool www] child 12469 started
And that's all
Now I'm going to show you my nginx configurations for the block and the nginx.conf
Nginx.conf
user nginx;
worker_processes 1;
worker_rlimit_nofile 1024;
pid /var/run/nginx.pid;
error_log /var/log/nginx/error.log;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
sendfile on;
server_tokens on;
types_hash_max_size 1024;
types_hash_bucket_size 512;
server_names_hash_bucket_size 64;
server_names_hash_max_size 512;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Nginx server block
server {
listen *:80;
server_name stage.mywebsite.com;
root /var/www/website_stage/current/src/public/;
set $maintenance "off";
if ($maintenance = "on") {
return 503;
}
index index.php;
access_log /var/log/nginx/stage.mywebsite.com.access.log combined;
error_log /var/log/nginx/stage.mywebsite.com.error.log;
location ~ \.php$ {
root /var/www/website_stage/current/src/public/;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
}
location / {
root /var/www/website_stage/current/src/public/;
rewrite ^/(.+)/$ /$1 permanent;
try_files $uri $uri/ /index.php?query_string;
}
}
I'm using Nginx 1.8 on CentOS 7.
I hope you can help me.

Categories