Connection reset by peer while reading response header from upstream (NGINX) - php

Im trying to run the local project (php phalcon) using nginx on macOS but it seems nginx can't load the project correctly.
Here is my nginx log given :
2023/01/12 11:38:04 [error] 6170#0: *1 kevent() reported about an closed connection (54: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server: bahana.front, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9074", host: "127.0.0.1:7002"
2023/01/12 11:38:05 [error] 6170#0: *1 kevent() reported about an closed connection (54: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server: bahana.front, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9074", host: "127.0.0.1:7002", referrer: "http://127.0.0.1:7002/"
and here is my site nginx config : (for loading the php phalcon project)
server {
listen 7002;
root /Applications/XAMPP/xamppfiles/htdocs/bahana-front/bahana/public;
index index.php;
server_name bahana.front;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9074;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
also the php-fpm work well in the background (port 9074) :
So, what did i miss for the configuration, im little stuck and keep getting closed connection at nginx log and HTTP Error 502 (Bad Gateway) when accessing the site at http://127.0.0.1:7002, Gonna need your help, thanks.

Related

nginx1.8 Laravel 502 bad gateway error

SOLVED!
Using Virtualbox to setup Homestead vagrantbox
Here is the server configuration in the file dev.blog.com.conf
server {
listen 80;
server_name dev.blog.com;
root /vagrant/blog/public;
index index.php index.html index.htm;
location / {
index index.php index.html index.htm;
try_files $uri #rewrite;
}
location #rewrite {
rewrite ^ /index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
access_log /vagrant/logs/blog.access.log;
error_log /vagrant/logs/blog.error.log;
}
And in VagrantFile I've uncommented the line 'config.vm.network'
In My windows hosts file I've add this line
192.168.33.10 dev.blog.com
I keep restarting Nginx or refreshing the page,but still got the 502 bad gatway.
It's there some permission problem about my folder or other problems?
Log
2017/02/17 02:16:54 [error] 1717#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.33.1, server: dev.blog.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.33.10"
2017/02/17 02:17:02 [error] 1717#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.33.1, server: dev.blog.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.33.10"
I figured out the Problem,The new php configuration had been modified a little bit,so in the
vim /etc/php5/fpm/pool.d/www.conf
so the listen line should be listen=9000 instead of listen = /var/run/php5-fpm.sock

Nginx doesn't server subfolder api application (php-fpm)

I have following folder structure for my application
- css
- app
- js
- ...
- server (codeigniter)
-- system
-- application
-- index.php
- index.html (angularJS app)
this is my nginx.conf
server {
listen 80;
listen [::]:80;
root /var/www/html/myapp.com/public_html;
index index.html;
server_name myapp.com www.myapp.com;
location / {
index index.html;
}
location /server/ {
index /server/index.php;
try_files $uri /server/index.php/$uri;
}
location /twitter/ {
index /twitter/index.php;
try_files $uri /twitter/index.php/$uri;
}
location ~ \.php {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
#deny access to .htaccess files, if Apache's document root
#concurs with nginx's one
location ~ /\.ht {
deny all;
}
}
And this is the error i'm keep getting
2016/03/04 18:26:02 [error] 4577#0: *4 FastCGI sent in stderr: "Unable to open primary script: /home/valor/development/myapp.com/public_html/server/index.php (No such file or directory)" while reading response header from upstream, client: 127.0.0.1, server: myapp.com, request: "GET /server/api/users/isLoggedIn HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "myapp.com", referrer: "http://myapp.com/"
2016/03/04 18:26:02 [error] 4577#0: *3 FastCGI sent in stderr: "Unable to open primary script: /home/valor/development/myapp.com/public_html/server/index.php (No such file or directory)" while reading response header from upstream, client: 127.0.0.1, server: myapp.com, request: "GET /server/api/categories HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "myapp.com", referrer: "http://myapp.com/"
2016/03/04 18:26:03 [error] 4577#0: *3 FastCGI sent in stderr: "Unable to open primary script: /home/valor/development/myapp.com/public_html/server/index.php (No such file or directory)" while reading response header from upstream, client: 127.0.0.1, server: myapp.com, request: "GET /server/api/products/latest/16 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "myapp.com", referrer: "http://myapp.com/"
Page is displayed correctly i just can reach api resources in sub folder.
Can you guy help me out what i'm doing wrong?
If you need any additional information's please let me know and i will provide
Thank you
Based on user #semm0 (link)
This might be a permission problem, possibly caused by AppArmor. Please review this answer to see possible solution. I don't want to steal the answer, therefore linking to it.
EDIT: the problem might now occur from the php-fpm configuration. Please open /etc/php5/fpm/pool.d/www.conf with your favorite editor and uncomment the following lines:
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
and don't forget to restart the php server with:
service php5-fpm restart

Windows 10 - Nginx & Symfony 3 configs

I am trying to setup my environment using Nginx and a fresh project from Symfony 3, both work fine on their own (either starting Nginx by launching php-cgi.exe -b 127.0.0.1:9000 or starting the Symfony 3 project with server:run), however, I can't get Symfony working through Nginx.
The error message I get in my log goes like this:
2016/02/21 00:36:33 [error] 6260#1732: *1 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: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"
And this is my code in nginx.conf for the server section so far:
server {
listen 80;
server_name localhost;
root www/projects/mysite.com/web;
rewrite ^/app\.php/?(.*)$ /$1 permanent;
location / {
index app.php;
try_files $uri #rewriteapp;
}
location #rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
I have placed the 50x.html file in my /web folder and it does show up correctly after the timeout...
I can understand you are using Unix / Linux machine. This is because you haven't enabled (granted the privilege for upstream).
setsebool -P httpd_can_network_connect true
The upstream blocked by selinux by default. Please let me know if this fixes.
Thanks.

Symfony2 + nginx + phpfpm login_check fail

When login form requests login_check action, nginx throws 502 error.
Cannot figure out why is this happens
2015/11/07 18:49:37 [error] 26038#0: *2 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server: test.local, request: "POST /admin/login/check HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "test.local", referrer: "http://test.local/admin/login"
site nginx config:
server {
server_name test.local;
root /var/www/test.local/web;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app_dev.php$is_args$args;
}
location ~ .php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
error_log /var/log/nginx/test.local_error.log;
access_log /var/log/nginx/test.local_access.log;
}

nginx rewrite issues

I just switched from apache to nginx, just for testing and I experience the following problem. I am using this config for nginx
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
Now I have a php script makethumbs.php that automatically resize images displayed on my website. With apache, works just fine. With nginx I get this error:
2011/12/29 15:13:17 [error] 15548#0: *9 open() "/usr/share/nginx/html/makethumbs.php/0737438664-22.jpg" failed (20: Not a directory), client: 193.138.192.81, server: www.escortele.eu, request: "GET /makethumbs.php/0737438664-22.jpg?width=48&height=64&image=/members/escorte/0737438664-22.jpg HTTP/1.1", host: "escortele.eu:88", referrer: "http://escortele.eu:88/"
The problem is that it sees makethumbs.php as a directory and it should be a script not a directory.
I can't figure it out what rewrite rule to use, only for makethumbs.php so it acts like a script and not like a directory.
You should have pasted the rest of your configuration file because what you pasted has nothing to do with what you want.
That error is because you have "try_files $uri $uri/ /index.php;" somewhere in your config. You need to remove the $uri/ from that to fix the error you pasted.
The problem is not in
location / {
try_files $uri $uri/ /index.php;
}
That part is good. You need it.
Since you didn't post your entire config I can't be sure what you're problem is, but I can tell you what my problem was in the same type of situation. Following the recomendation of others, I had a location defined for image files as follows:
location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ {
expires max;
log_not_found off;
}
That was the problem. Because Nginx uses the most specific location that matches, the URL ending with .jpg would match this location and this location doesn't tell it to use index.php. I just got rid of this location and it worked.
Additional tips:
define your root in the server block and not in location blocks.
I don't think you don't need "fastcgi_index index.php;"
You don't need to hard-code your document root:
change
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
to
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
This is the script I am using for thumbnails: http://escorte.pro:88/makethumbs.txt
My nginx config is as follows: http://escorte.pro:88/nginx.txt
The error I get is:
2014/08/27 14:59:07 [error] 20986#0: *86 open() "/usr/share/nginx/html/escorte.pro/makethumbs.php/0737835261-79.jpg" failed (20: Not a directory), client: 83.166.220.234, server: escorte.pro, request: "GET /makethumbs.php/0737835261-79.jpg?width=48&height=64&image=/members/escorte/0737835261-79.jpg HTTP/1.1", host: "escorte.pro:88", referrer: "http://escorte.pro:88/"
2014/08/27 14:59:07 [error] 20986#0: *87 open() "/usr/share/nginx/html/escorte.pro/makethumbs.php/0743844296-60.jpg" failed (20: Not a directory), client: 83.166.220.234, server: escorte.pro, request: "GET /makethumbs.php/0743844296-60.jpg?width=48&height=64&image=/members/escorte/0743844296-60.jpg HTTP/1.1", host: "escorte.pro:88", referrer: "http://escorte.pro:88/"
The makethumbs.php script works perfectly fine on apache
Any clues?
I hope this info si more complete than the previous...

Categories