Windows 10 - Nginx & Symfony 3 configs - php

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.

Related

Random Nginx Upstream Timeout Error To Proxy

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?

(111: Connection refused) while connecting to upstream on nginx

So I made an alternative domain to a site of mine, using nginx but that error keeps coming up.
The original site works just fine, but the alternate domain shows this error.
2021/01/04 15:14:27 [error] 2007#2007: *269 connect() failed (111:
Connection refused) while connecting to upstream, client:
35.209.169.6, server: cocknutsandball.com, request: "GET /sh4 HTTP/1.1", upstream: "http://127.0.0.1:9000/sh4", host:
"104.244.79.32"
Here is what I tried to do:
reload nginx and php8.0-fpm
disable any firewall
for the alternate domain
'''
server {
listen 80;
server_name cocknutsandball.com www.cocknutsandball.com;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:9000;
}
}
'''
For the main domain that works
'''
server {
listen 127.0.0.1:80 default_server;
root /var/www/;
index chat.php lang_en.php emoji.css;
server_name ylwebs62zfllr4hhailwwysq2erzoxqcwqhfokkzimi73c2n4fp3mspad.o$
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
include fastcgi.conf;
}
error_log
/root/error_log;
access_log
/root/access_log;
}
'''
OK quick update: I changed the config to be completely identical to the one for the working domain but change the domain so now it is:
server {
listen 127.0.0.1:80;
root /var/www/;
index chat.php lang_en.php emoji.css;
server_name cocknutsandball.com;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
include fastcgi.conf;
}
error_log
/root/error_log;
access_log
/root/access_log;
}
but now im getting the same exact error
just to clarify some things:
I have restarted nginx
i have made sure that the configuration syntax is working(which it was)
i have changed the index to another file to see if thats a problem
i made sure all of the ports are being listened to
i have but the domain into the original domain config, still the same error on the alternate domain
I have referred to the manual, and a lot of other guides on the internet, i just have a really difficult time understanding it

unable to get hhvm working with nginx

I have nginx and hhvm installed and running as processes on a ubuntu VM. The configs are copied below. I have an index.php file in /usr/share/nginx/html (pointed to by nginx) but when I try to access the site beign served by nginx, I get the following error about hhvm:
/var/log/nginx/error.log
2016/10/04 12:03:05 [crit] 12443#0: *1 connect() to unix:/var/run/hhvm/hhvm.sock failed (2: No such file or directory) while connecting to upstr
eam, client: xx.xxx.xxx.xxx, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/hhvm/hhvm.sock:", host: "xx.xx.xx.xx"
Nginx config (part of config)
server {
listen 80 default_server;
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
index index.php;
try_files $uri $uri/ $uri/index.php$args /index.php$args;
}
location /mysql {
index index.php;
}
location ~* \.(php)$ {
try_files $uri = 404;
location ~ \..*/.*\.php$ {return 404;}
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_keep_conn on;
fastcgi_pass unix:/var/run/hhvm/hhvm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
I have checked - bothh nginx and hhvm processes are running. Any thoughts on how to troubleshoot this further?
Update:
I changed the server.ini file in /etc/hhvm to the following and restarted the service but it does not appear to have done the job
hhvm.server.file.socket=/var/run/hhvm/hhvm.sock
I commented out the 9000 port being used previously.
Update:
After making the server.init change and restarting hhvm, I get the following error in /var/log/hhvm/error.log:
Unable to read pid file /var/run/hhvm/pid for any meaningful pid
Unable to read pid file /var/run/hhvm/pid for any meaningful pid
Unable to read pid file /var/run/hhvm/pid for any meaningful pid
Unable to read pid file /var/run/hhvm/pid for any meaningful pid
Unable to read pid file /var/run/hhvm/pid for any meaningful pid
Unable to start page server
Shutting down due to failure(s) to bind in HttpServer::runAndExitProcess
The /var/run/hhvm directory is owned by www-data
I ended up running hhvm on port 9000 and pointed nginx (fasgcgi_pas) to point to the port (instead of using the file socket option).

502 Bad Gateway with PHP7 and Nginx 1.9.9

I'm getting a 502 Bad Gateway error with PHP7 and nginx 1.9.9 installed on Ubuntu 14.04 when I try to access any .php files. .html files load as expected.
I've updated the default.conf to:
server {
listen 80 default_server;
root /usr/share/nginx/html;
index index.html index.htm index.php;
server_name localhost;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
I've updated php.ini with cgi.fix_pathinfo = 0 and then rebooted the server, and am still getting the 502 error with all .php files. I have checked to ensure php7.0-fpm.sock is installed and in the proper location.
This is the error I'm getting from the nginx log 2016/01/19 19:14:54 [error] 1466#1466: *1 open() "/usr/share/nginx/html/xmlrpc.php" failed (2: No such file or directory), client: 85.159.237.13, server: localhost, request: "POST /xmlrpc.php HTTP/1.0", host: "my.ip.address"
I've searched for the answer for quite a while and I'm out of ideas. Does anyone have any suggestions?
This is mostly because your nginx and php7.0-fpm were not run under the same user. Edit nginx.conf and change "user nginx" to "user www-data"
By the way, "client: 85.159.237.13", that was a script boy, I think.

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