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
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?
hi i got a problem running nodejs in my php project, im planning run my apps in nginx, nodejs, php-fpm, and pm2
but i tryna access the test file its doesn't work and the nginx error log is like this
2022/03/10 21:04:04 [error] 14875#14875: *12 connect() failed (111: Connection refused) while connecting to upstream, client: ips, server: domainname, request: "GET /test.js HTTP/1.1", upstream: "http://[::1]:7000/test.js", host: "domainname
and this is my nginx configuration file
#Names a server and declares the listening port
server {
listen 80;
server_name domainname;
#Configures the publicly served root directory
#Configures the index file to be served
root /var/www/domainname;
index index.html index.htm;
#These lines create a bypass for certain pathnames
#www.example.com/test.js is now routed to port 3000
#instead of port 80
location ~* \.(js)$ {
proxy_pass http://localhost:7000;
proxy_set_header Host $host;
}
}
i already install nodejs but the .js file is not work, after the js work ill try to add some conf for nginx php
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
but the problem right now is the .js file is not work how to solve that problem ? i already allow firewall at 7000/tcp but its not working
I was running Ubuntu server 20.04 quite successfully with Ired mail and 2 websites, one of them with WordPress.
I wanted to install Nextcloud, to do that I had to reinstall php-fpm to generate php7.4-fpm.sock. After this Nextcloud worked, but my other websites stopped working with error '502 Bad Gateway'.
So to say the least, I'm very confused!
I followed this article to install Nextcloud and set up the sites-enabled .conf file as per instructions: https://www.linuxbabe.com/ubuntu/install-nextcloud-ubuntu-20-04-nginx-lemp-stack/amp
I think I understand that the .conf file used to listen on 127.0.0.1:XXXX and now listens on php7.4-fpm.sock?
Here is the .conf file that I have put together for my website after re-installing php-fpm:
#
# Note: This file must be loaded before other virtual host config files,
#
# HTTPS
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name SOMEWEBSITE www.SOMEWEBSITE;
error_log /var/log/nginx/localhost.error_log info;
root /var/www/SOMEWEBSITE/html;
index index.php index.html;
include /etc/nginx/templates/misc.tmpl;
include /etc/nginx/templates/ssl.tmpl;
include /etc/nginx/templates/iredadmin.tmpl;
include /etc/nginx/templates/roundcube.tmpl;
include /etc/nginx/templates/sogo.tmpl;
include /etc/nginx/templates/netdata.tmpl;
include /etc/nginx/templates/php-catchall.tmpl;
include /etc/nginx/templates/stub_status.tmpl;
location / {
try_files $uri $uri/ /index.php?q=$uri$args;
}
# PHP handling
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
ssl_certificate /etc/letsencrypt/live/SOMEWEBSITE/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/SOMEWEBSITE/privkey.pem; # managed by Certbot
}
# Redirect http to https
server {
listen 80;
listen [::]:80;
server_name SOMEWEBSITE www.SOMEWEBSITE;
return 301 https://$host$request_uri;
}
I have checked the file permissions for php7.4-fpm.sock
ll /var/run/php/ | grep php
-rw-r--r-- 1 root root 3 May 22 21:13 php7.4-fpm.pid
srw-rw---- 1 www-data www-data 0 May 22 21:13 php7.4-fpm.sock=
lrwxrwxrwx 1 root root 30 May 22 21:13 php-fpm.sock -> /etc/alternatives/php-fpm.sock=
and I think it looks ok.
here is the log file:
2021/05/23 20:32:52 [error] 43596#43596: *305 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xx.xxx.xxx, server: SOMEWEBSITE, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9999", host: "SOMEWEBSITE"
2021/05/23 20:32:53 [info] 43596#43596: *305 client xx.xx.xxx.xxx closed keepalive connection
Any Ideas? Need any more information? Thank you in advance for looking.
PHP-FPM can listen using two method for accepting fastcgi request. using TCP Socket or with Unix Socket.
You can sepecify it in php-fpm configuration, In Ubuntu the configuration is in /etc/php/7.4/fpm/pool.d/www.conf and check listen configuration.
If you want to use unix socket, use configuration below.
listen = /run/php/php7.4-fpm.sock
For TCP Socket.
listen = 127.0.0.1:9000
Next in nginx you can specify fastcgi_pass based on fpm configuration. If you using Unix socket, all your website, include Nextcloud must be using Unix Socket.
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
If you using TCP Socket, you must change the nginx configuration for Nextcloud to pass from TCP Socket.
fastcgi_pass 127.0.0.1:9000;
I have faced this issue as well. the problem is php-fpm didnt listen port 9999 (In my case i use port 9999). To make /mail/ work. u need to change below config file. change ip:port change to socket
/etc/php/fpm/pool.d/www.conf
listen = /var/run/php/php7.2-fpm.sock
/etc/nginx/templates/fastcgi_php.tmpl
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
I am new to Nginx and have just started to give it a try on Windows using WinNMP I have successfully installed and can play with basic PHP. Then I move on to trying Laravel 5.5. The installation using composer seems success and it gives the laravel error page:
The url I used to call this page is http://localhost/mylaraveltest/public/
I have checked the Laravel error log file but no error message there. I then checked the error message from Nginx and see this:
2018/03/28 11:30:20 [warn] 8560#11828: *21 upstream server temporarily disabled while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /mylaraveltest/public/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9003", host: "localhost"
2018/03/28 11:30:20 [error] 8560#11828: *21 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 /mylaraveltest/public/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9003", host: "localhost"
It seems to be the problem related to routing problem. From the official page, it seems that I should add the following:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
The problem is, it does not mentioned where should I put this line in.... and it seems to be so obvious that all guides I found by Google simply just focus on what to add but don't mention where to add this line.
I make a guess and put it inside the server bracket of nginx.conf, but the problem is still there. If this is the wrong place to add, where should it be put? And if this is the correct place, then what else can cause the problem?
The file you are looking for is (usually) located in /etc/nginx/sites-enabled/site00.app
And should contain something like:
server {
listen 80;
listen 443 ssl http2;
server_name .site00.app;
root "/home/vagrant/sites/site00/site/public";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/site00.app-error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
ssl_certificate /etc/nginx/ssl/site00.app.crt;
ssl_certificate_key /etc/nginx/ssl/site00.app.key;
}
Where site00.app both in the filename and in the config, is the name and tld of your application.
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.