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.
Related
I can't seem to figure this error out or how to debug it. Randomly on my NginX PHP-FPM Setup, my server stops acceting POST, PUT, and DELETE request. But it still will accept GET request, so people can browse the website. An example of the error message is here:
2022/09/06 20:57:44 [warn] 52#52: *20475 upstream server temporarily disabled while connecting to upstream, client: 10.x.x.x, server: example.com, request: "POST /api/accounts/login HTTP/1.1", upstream: "https://52.xxx.xxx.xx:443//accounts/login", host: "www.example.com", referrer: "https://www.example.com/login"
To fix the issue I just do a restart of nginx and problem solved. Now I noticed the POST is to:
POST /api/accounts/login
and the Upstream is to
https://xxx.xxx.xxx.xx:443//accounts/login
The /api route POST request, and it seems that Nginx is removing the /api for some reason when forwarding to the proxy. My Nginx configuration is this:
server {
listen 80;
listen [::]:80;
server_name .example.com www.example.com _ default_server;
if ($http_x_forwarded_proto = 'http'){
return 301 https://$host$request_uri;
}
location / {
root /var/www/public_html/;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?rt=$uri&$args;
}
location /api {
proxy_pass_header Set-Cookie;
proxy_pass_header P3P;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Fowarded-Host $host;
proxy_pass https://api.example.com/;
proxy_connect_timeout 5s;
}
}
Why does it appear that Nginx is randomly removing the /api and why is restarting nginx fixing this issue?
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.
php5 over nginx is giving 502 bad gateway but working fine with apache2.Am running Apache on default port and nginx on port 81.
error log message:
2016/12/02 12:32:05 [alert] 10119#0: 768 worker_connections are not enough
2016/12/02 12:32:05 [error] 10119#0: *2295 recv() failed (104: Connection reset by peer) while
reading response header from upstream, client: 127.0.0.1, server: localhost, request:
"GET /index.php HTTP/1.0", upstream: "http://127.0.0.1:81/index.php", host: "127.0.0.1".
My custom server file:
server {
listen 81;
root /var/www/html/laralvelproj/public/;
index index.html index.htm index.php;
server_name localhost;
error_log /var/www/html/yoyogrx.com-error.log error;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:81;
}
}
Can someone please help me out here.
Running shopware 5 on a Debian Jessie machine with nginx and php5-fpm, we get very often a 502 Bad Gateway. This happens mostly in backend when longer operations are working like thumbnail creation, even if this is done within small chunks of single ajax requests.
The used server with 64 GB RAM and 16 Cores is sleeping at all, because there is no real traffic on it. We use it like a staging system currently unless we have fixed all errors like this one.
Error log:
In the nginx-error log the following lines can be found then:
[error] 20524#0: *175 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xx.xx.xx, server: domain.com, request: "POST /backend/MediaManager/createThumbnails HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.domain.com", referrer: "http://www.domain.com/backend/"
[error] 20524#0: *175 no live upstreams while connecting to upstream, client: xx.xx.xx.xx, server: domain.com, request: "POST /backend/Log/createLog HTTP/1.1", upstream: "fastcgi://php-fpm", host: "www.domain.com", referrer: "http://www.domain.com/backend/"
[error] 20524#0: *175 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xx.xx.xx, server: domain.com, request: "GET /backend/login/getLoginStatus?_dc=1457014588680 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.domain.com", referrer: "http://www.domain.com/backend/"
[error] 20522#0: *209 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xx.xx.xx, server: domain.com, request: "GET /backend/login/getLoginStatus?_dc=1457014618682 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.domain.com", referrer: "http://www.domain.com/backend/"
Maybe it is notable, that at first lot of "*175 connect" errors occure and then finally a "*209 connect".
Config files:
I'll try to post only significant lines related to this topic and will leave out all those lines which are commented out.
php-fpm:
/etc/php5-fpm/pool.d/www.conf:
[www]
user = www-data
group = www-data
listen = /var/run/php5-fpm.sock
listen.owner = www-data
listen.group = www-data
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
nginx:
/etc/nginx/nginx.conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
multi_accept on;
}
http {
## MIME types.
include /etc/nginx/mime.types;
default_type application/octet-stream;
## Default log and error files.
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
## Use sendfile() syscall to speed up I/O operations and speed up
## static file serving.
sendfile on;
## Handling of IPs in proxied and load balancing situations.
# set_real_ip_from 192.168.1.0/24; # set to your proxies ip or range
# real_ip_header X-Forwarded-For;
## Timeouts.
client_body_timeout 60;
client_header_timeout 60;
keepalive_timeout 10 10;
send_timeout 60;
## Reset lingering timed out connections. Deflect DDoS.
reset_timedout_connection on;
## Body size.
client_max_body_size 10m;
## TCP options.
tcp_nodelay on;
## Optimization of socket handling when using sendfile.
tcp_nopush on;
## Compression.
gzip on;
gzip_buffers 16 8k;
gzip_comp_level 1;
gzip_http_version 1.1;
gzip_min_length 10;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon application/vnd.ms-fontobject font/opentype application/x-font-ttf;
gzip_vary on;
gzip_proxied any; # Compression for all requests.
gzip_disable "msie6";
## Hide the Nginx version number.
server_tokens off;
## Upstream to abstract backend connection(s) for PHP.
upstream php-fpm {
server unix:/var/run/php5-fpm.sock;
# server 127.0.0.1:9000;
## Create a backend connection cache.
keepalive 32;
}
## Include additional configs
include /etc/nginx/conf.d/*.conf;
## Include all vhosts.
include /etc/nginx/sites-enabled/*;
}
/etc/nginx/sites-available/site.conf:
server {
listen 80;
listen 443 ssl;
server_name xxxxxxxx.com;
root /var/www/shopware;
## Access and error logs.
access_log /var/log/nginx/xxxxxxxx.com.access.log;
error_log /var/log/nginx/xxxxxxxx.com.error.log;
## leaving out lots of shopware/mediafiles-related settings
## ....
## continue:
location ~ \.php$ {
try_files $uri $uri/ =404;
## NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
fastcgi_split_path_info ^(.+\.php)(/.+)$;
## required for upstream keepalive
# disabled due to failed connections
#fastcgi_keep_conn on;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SHOPWARE_ENV $shopware_env if_not_empty;
fastcgi_param ENV $shopware_env if_not_empty; # BC for older SW versions
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
client_max_body_size 24M;
client_body_buffer_size 128k;
## upstream "php-fpm" must be configured in http context
fastcgi_pass php-fpm;
}
}
What to do now? Please let me now if i should provide further information to this question.
Update
After applying nginx- and fpm-settings from #peixotorms, the errors in nginx-logs changed to:
30 upstream timed out (110: Connection timed out) while reading response header from upstream
But the issue itself isn't solved. It has just another face...
It might sound strange to you, but your problem is most probably due to the fact that you're running PHP on a socket instead of a tcp port. You will start seeing 502 errors (and others) when you have around 300 concurrent requests (sometimes less) to php on a socket configuration.
Also your pm.max_children is way too low, unless you want to limit your server to around 5 simultaneous php requests maximum: http://php.net/manual/en/install.fpm.configuration.php
Configure it this way, and those errors should go away:
For your nginx.conf change the following values:
worker_processes 4;
worker_rlimit_nofile 750000;
# handles connection stuff
events {
worker_connections 50000;
multi_accept on;
use epoll;
}
upstream php-fpm {
keepalive 30;
server 127.0.0.1:9001;
}
Your /etc/php5-fpm/pool.d/www.conf
(Use these settings because you have plenty or RAM and CPU)
[www]
user = www-data
group = www-data
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
listen = 127.0.0.1:9001
listen.allowed_clients = 127.0.0.1
listen.backlog = 65000
pm = dynamic
pm.max_children = 1024
pm.start_servers = 8
pm.min_spare_servers = 4
pm.max_spare_servers = 16
pm.max_requests = 10000
Also add this on your location ~ \.php$ { block:
location ~ \.php$ {
try_files $uri $uri/ =404;
## NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
fastcgi_split_path_info ^(.+\.php)(/.+)$;
## required for upstream keepalive
# disabled due to failed connections
#fastcgi_keep_conn on;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SHOPWARE_ENV $shopware_env if_not_empty;
fastcgi_param ENV $shopware_env if_not_empty; # BC for older SW versions
fastcgi_keep_conn on;
fastcgi_connect_timeout 20s;
fastcgi_send_timeout 60s;
fastcgi_read_timeout 60s;
fastcgi_pass php-fpm;
}
EDIT:
Change the values below on your /etc/php5/fpm/php.ini file to this and restart:
safe_mode = Off
output_buffering = Off
zlib.output_compression = Off
max_execution_time = 900
max_input_time = 900
memory_limit = 2048M
post_max_size = 120M
file_uploads = On
upload_max_filesize = 120M
Try binding to 0.0.0.0:9000:
listen = 0.0.0.0:9000
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.