nginx1.8 Laravel 502 bad gateway error - php

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

Related

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

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.

NGINX is giving 502 bad gateway but working fine with Apache2 on Ubnatu 14.04

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.

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.

Why homebrew installed nginx only serve files in the default doc root?

I installed nginx (with --fpm) on Mac OS X through homebrew, but I can't make it serve php files (html files are OK). Here is the error:
[error] 46118#0: *1 kevent() reported that connect() failed (61:
Connection refused) 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"
below is my site conf file.
server {
listen 80;
root /Users/me/Sites/test/public/;
index index.html index.php;
server_name localhost;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
error_log /var/log/nginx/error.log;
location ~ \.php$ {
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /Users/me/Sites/test/public/scripts$fastcgi_script_name;
include /usr/local/etc/nginx/fastcgi_params;
}
}
I'm not very well versed in the fpm setup. What am I doing wrong? Any help would be appreciated, thanx.
Environment:
Mac OS X 10.10.2
nginx:1.6.2

Categories