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?
Related
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
This has been frustrating me to no end. I've been getting that classic line:
No 'Access-Control-Allow-Origin' header is present on the requested
resource.
I'm running the latest stable Nginx on Ubuntu 16.04, with a Swoole server configured to handle the Laravel PHP requests in PHP 7.2. As far as I know it's all working.
The Laravel api is on one subdomain, and the frontend is an angular on another subdomain. Up till now everything's worked, so I've been trying to configure CORS on the backend site.
Despite having it configured, it's not recognising that exists. Yes I restart nginx every time I update the config. Caching at the moment is off for dev purposes. Nginx config shortened below:
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
listen [::]:80;
root /var/www/sub.example.com/;
index index.php;
server_name sub.example.com www.sub.example.com;
[redirect 301 part]
[php location]
}
## https://example.com redirects to https://www.example.com
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name www.sub.example.com;
[SSL certs]
[redirect 301 to sub.example.com]
}
## Serves https://sub.example.com
server {
server_name lhb.luminuxlab.com;
listen 443 ssl http2 ;
listen [::]:443 ssl http2;
[SSL certs]
root /var/www/sub.example.com;
index index.php;
location / {
try_files $uri $uri/ /index.php?#swoole;
}
[php stuff]
location #swoole {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow_Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Ra$
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
proxy_set_header Host $http_host;
proxy_set_header Scheme $scheme;
proxy_set_header SERVER_PORT $server_port;
proxy_set_header REMOTE_ADDR $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
# IF https
proxy_set_header HTTPS "on";
proxy_pass http://127.0.0.1:1215$query_string;
}
}
I've tried shifting the headers to a bunch of different places but I've had no luck getting a change in response, ping the server with curl
curl -H "Access-Control-Request-Method: GET" -H "Origin: http://front.example.com" --head http://back.example.com/
Gives no useful information and the CORS headers don't seem to be included. I've tried different variations and configurations of the CORS header commands and no response.
Anybody got an idea of what might be going wrong?
Ok problem solved. After more experimentation I found that the correct location for the access control headers was in the final https redirect before the proxy redirect to swoole. Like so:
## Serves https://sub.example.com
server {
server_name sub.example.com;
listen 443 ssl http2 ;
listen [::]:443 ssl http2;
[ssl stuff]
add_header 'Access-Control-Allow-Origin' 'https://front.example.com';
add_header 'Access-Control-Allow_Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,Content-Type,Content-Range,Range';
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS';
root /var/www/sub.example.com/;
....
location #swoole {
....
proxy_pass http://127.0.0.1:1215$query_string;
}
}
Hope this helps people in the future.
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.
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.
After setting apache2 to listen on port 3000 and server php files(wordpress) hitting blog.mysite.com:3000 loads my wordpress install no problem. Then I set up nginx listening on port 80 as a proxy to apache. This is working fine, my only issue is that when users hit blog.mysite.com, its get redirected to blog.mysite.com:3000 instead and this is not the desired behavior. Looked online for a few solutions involving adding some php code to my wp-config.php but didnt worked. Any help with this?
EDIT:
server {
listen 80 default_server;
server_name appsrd.devmbs.com;
root /home/ubuntu/projecs/APPS-RD;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /home/ubuntu/projects/APPS-RD;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
proxy_pass http://127.0.0.1:3000;
proxy_buffering on;
proxy_buffers 12 12k;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect http://appsrd.devmbs.com:3000 http://appsrd.devmbs.com;
}
}
EDIT:
/wp-admin is being displayed but the root of the site, is ging in a redirected loop.
127.0.0.1 - - [03/Sep/2012:12:29:25 +0000] "GET /index.php HTTP/1.0" 301 529 "http://appsrd.devmbs.com/wp-admin/options-general.php" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1"
This request is getting fired like 12 to 15 times.
EDIT:
Weirdest thing, I deleted the database and went into http://www.mysite.com, and the redirect loop was gone, I got a msg that wordpress couldn't find a DB which was supposed to happens. Then I created a new database, ran the wordpress install and the same arises. The admin works fine but the site page gets redirect loop.
Issue was that in the wordpress setting I had wrong Address so it was adding :3000 at the end of the url. Since the title of this question no longer represent my current issue I will close it and create a new question.