NginX 500 (Internal Server) Error - php

I've been having some problems with my NginX installation. I'm not getting any errors, however, I get the classic "500 - Internal Server Error" when I try to go to my localhost address.
This is my config:
user nobody; ## Default: nobody
worker_processes 5; ## Default: 1
error_log logs/error.log;
pid logs/nginx.pid;
worker_rlimit_nofile 8192;
events {
worker_connections 4096; ## Default: 1024
}
http {
include mime.types;
include fastcgi.conf;
index index index.html index.htm index.php;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
tcp_nopush on;
server_names_hash_bucket_size 128; # this seems to be required for some vhosts
server { # simple reverse-proxy
listen 80;
access_log logs/access.log main;
# serve static files
location ~ ^/(images|javascript|js|css|flash|media|static)/ {
root /Library/Testing/public_html;
expires 30d;
}
# pass requests for dynamic content to rails/turbogears/zope, et al
location / {
proxy_pass http://127.0.0.1:8080;
}
}
upstream big_server_com {
server 127.0.0.3:8000 weight=5;
server 127.0.0.3:8001 weight=5;
server 192.168.0.1:8000;
server 192.168.0.1:8001;
}
server { # simple load balancing
listen 80;
server_name big.server.com;
access_log logs/big.server.access.log main;
location / {
proxy_pass http://big_server_com;
}
}
}
What's the issue? I looked at other related SOF questions, but none fixed my problem. Thank you.
EDIT: My log is now saying: 2015/07/26 13:43:40 [error] 2494#0: *1 kevent() reported that connect() failed (61: Connection refused) while connecting to upstream, client: 127.0.0.1, server: , request: "GET /index.php HTTP/1.1", upstream: "http://127.0.0.1:8080/index.php", host: "localhost"
When I attempt to load the page "localhost/index.php"

I fixed my issue. It turns out I forgot to activate php-fpm: sudo php-fpm does the trick.

Related

Joomla Index.php not working PHP error error] 43979#0: *3 FastCGI sent in stderr:

I am trying to get joomla to work on nginx with postgresql. But i get this error in the error.log of nginx. I am running AlmaLinux8
10:24:55 [error] 43029#0: *3 FastCGI sent in stderr: "PHP message: PHP Warning: SessionHandler::read(): open(/var/lib/php/session/sess_pdma2qg4ua4jock4llrgqqfn0t, O_RDWR) failed: Permission denied (13) in /var/www/html/libraries/vendor/joomla/session/src/Storage/NativeStorage.php on line 478PHP message: PHP Warning: session_start(): Failed to read session data: user (path: /var/lib/php/session) in /var/www/html/libraries/vendor/joomla/session/src/Storage/NativeStorage.php on line 478PHP message: PHP Warning: SessionHandler::read(): open(/var/lib/php/session/sess_l85tvgu52694uvci3nnfm2iomr, O_RDWR) failed: Permission denied (13) in /var/www/html/libraries/vendor/joomla/session/src/Storage/NativeStorage.php on line 478PHP message: PHP Warning: session_start(): Failed to read session data: user (path: /var/lib/php/session) in /var/www/html/libraries/vendor/joomla/session/src/Storage/NativeStorage.php on line 478" while reading response header from upstream, client: 192.168.0.7, server: thematrix.local, request: "GET /installation/index.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "192.168.0.252"
2022/03/25 10:24:55 [error] 43029#0: *3 open() "/var/www/html/50x.html" failed (2: No such file or directory), client: 192.168.0.7, server: thematrix.local, request: "GET /installation/index.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock", host: "192.168.0.252"
This is when i just enter my ip into the browser.
My nginx conf file:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
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 thematrix.local www.thematrix.local;
root /var/www/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?$args;
index index.html index.htm index.php;
}
location ~ \.php$ {
include fastcgi.conf;
fastcgi_pass unix:/run/php/www.sock;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name thematrix.local www.thematrix.local;
root /var/www/html/;
index index.php index.html index.htm;
ssl_certificate "/etc/nginx/ssl/thematrix.local.crt";
ssl_certificate_key "/etc/nginx/ssl/thematrix.local.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers PROFILE=SYSTEM;
ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
try_files $uri $uri /index.php?$args;
index index.html index.htm index.php;
}
location ~ \.php$ {
include fastcgi.conf;
fastcgi_pass unix:/run/php/www.sock;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
The weird thing is, is that i can access every other file within de root folder like readme and a test.php file i made. Those work file but index.php just doesn't work.

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

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

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.

Nginx upstream timed out

So I have recently installed nginx and now It is giving me some kind of error and closing nginx every like.. 2 hours? How can I fix it? I am getting the same error just before it closes in the error log I also get a lot of other error in my error log if that is anything to do with it?
I used nginx on a windows 2008 server with PHP...
2015/04/06 14:07:29 [error] 5812#5480: *552 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while connecting to upstream, client: 108.162.229.140, server: http://mywebsite.com, request: "GET /assets/ajax/get_bar.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mywebsite.com", referrer: "http://mywebsite.com/play"
2015/04/06 14:07:31 [error] 5812#5480: *600 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while connecting to upstream, client: 141.101.98.47, server: centralrp.co.uk, request: "GET /assets/ajax/get_bar.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "centralrp.co.uk", referrer: "http://centralrp.co.uk/play"
2015/04/06 14:10:19 [error] 5812#5480: *663 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while connecting to upstream, client: 141.101.98.47, server: mywebsite.com, request: "GET /home HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mywebsite.com", referrer: "http://mywebsite.com/index"
2015/04/06 14:19:52 [error] 5812#5480: *665 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while connecting to upstream, client: 141.101.98.100, server: mywebsite.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mywebsite.com"
2015/04/06 14:21:29 [error] 5812#5480: *667 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while connecting to upstream, client: 141.101.98.100, server: mywebsite.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mywebsite.com", referrer: "http://mywebsite.com/"
That above is the error log and I ge tthem errors every time before it closes, and here is my config..
#user nobody;
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;
root /Dropbox/Website;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
rewrite ^/hk/(.*)$ /index.php?hk=$1;
rewrite ^/(|/)$ /index.php?url=$1;
rewrite ^/([a-zA-Z0-9_-]+)(|/)$ /index.php?url=$1;
rewrite ^/(.*).htm$ /$1.php;
rewrite ^/business/manage/(.*)/(.*)/?$ /index.php?bm=$2&cid=$1;
rewrite ^/tickets/manage/(.*)/(.*) /index.php?url=manage_ticket&t=$1 last;
}
#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$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME C:/Dropbox/Website/$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;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
Add to location
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
Example,
location /cron/ {
...
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}
Since you are using fastcgi you may actually need to set fastcgi_read_timeout.
Here's the link : http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_read_timeout
location ~ .php$ {
fastcgi_read_timeout 600s;
}
I'm not quite familiar with the diagnoses of such problems, but there are some clues you might check on your system. "upstream timeout" might be caused by too many client requests, or that somewhere in the request handling php code is blocked, due to network/dns/database/etc failure and the default timeout is too long, thus fastcgi is blocked and not able to handle subsequent requests. Maybe you could check fastcgi or your php code alone first without nginx to validate that it's functioning well.

serve multiple directories in ngnix

I am trying to setup ngnix on my vps to serve different stuff e.g
examplesite.com/ (main site)
examplesite.com/pro/ (sub app)
examplesite.com/ad/
I wanted to be able to run different php apps from these directories.
My first task was to get examplesite.com/pro site working but I am having problems.
Please could someone help me ?
I just want to be able to run different things. I am trying install prosper202 on the /pro/ directory.
My default.conf file :
server {
listen 80;
server_name .exmaple.com;
root /usr/share/nginx/html;
client_max_body_size 512M;
# Default location settings
location / {
index index.php;
}
location /pro {
index index.php;
try_files $uri $uri/ pro/index.php?$args;
}
# Redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# Pass the PHP scripts to FastCGI server (locally with unix: param to avoid network overhead)
location ~ \.php$ {
# Prevent Zero-day exploit
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
---------------------------ngnix.conf-------------------------------------
user nginx;
worker_processes 4;
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;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
}
My error.log file :
2014/11/06 11:51:41 [error] 3152#0: *1 directory index of "/usr/share/nginx/html/" is forbidden, client: 14.16.105.135, server: , request: "GET / HTTP/1.1", host: "IP" 2014/11/06 11:54:39 [error] 3218#0: *1 directory index of "/usr/share/nginx/html/" is forbidden, client: 14.176.105.135, server: , request: "GET / HTTP/1.1", host: "IP"
There's a slash missing in your try_files directive.
Replace :
pro/index.php?$args
With :
/pro/index.php$is_args$args.

Categories