RESOLVED NginX location / SafariPushNotification agent 404 on request - nginx

I am in need of some NginX expertise.
I am configuring a Safari Push Notifications web service with NginX. When the front end requests permission, the Safari agent fails to connect and fetch the push package with a 404:
NginX access log:
159.192.217.13 - - [09/Jul/2018:06:26:15 +0100] "POST /push/v2/pushPackages/web.com.domain.co HTTP/1.1" 404 56 "-" "SafariNotificationAgent (unknown version) CFNetwork/901.1 Darwin/17.6.0 (x86_64)" "-"
159.192.217.13 - - [09/Jul/2018:06:26:15 +0100] "POST /push/v1/pushPackages/web.com.domain.co HTTP/1.1" 301 185 "-" "SafariNotificationAgent (unknown version) CFNetwork/901.1 Darwin/17.6.0 (x86_64)" "-"
159.192.217.13 - - [09/Jul/2018:06:26:16 +0100] "GET /push/v1/pushPackages/web.com.domain.co HTTP/1.1" 403 169 "-" "SafariNotificationAgent (unknown version) CFNetwork/901.1 Darwin/17.6.0 (x86_64)" "-"
NginX error log:
2018/07/09 06:26:15 [error] 2774#0: *23 FastCGI sent in stderr: "Unable to open primary script: /www/data/push/v2/pushPackages/web.com.domain.co (No such file or directory)" while reading response header from upstream, client: 159.192.217.13, server: domain.com, request: "POST /push/v2/pushPackages/web.com.domain.co HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "domain.com"
2018/07/09 06:26:16 [error] 2774#0: *23 directory index of "/www/data/push/v1/pushPackages/web.com.domain.co/" is forbidden, client: 159.192.217.13, server: domain.com, request: "GET /push/v1/pushPackages/web.com.domain.co/ HTTP/1.1", host: "domain.com"
2018/07/09 06:26:18 [error] 2774#0: *25 directory index of "/www/data/push/v1/log/" is forbidden, client: 159.192.217.13, server: domain.com, request: "GET /push/v1/log/ HTTP/1.1", host: "domain.com"
(replaced server with domain.com)
NginX location conf:
location /push/v2/pushPackages/web.com.domain.co {
add_header "Access-Control-Allow-Origin" *;
allow all;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
I am convinced this configuration is not correct.
It is pointing to the directory /push/v2/pushPackages/web.com.domain.co where index.php then generates the push package zip, however it appears that index cannot be found.

Related

Nginx + WordPress pretty permalinks return 404

Stuck even after having gone through all nginx + WordPress permalinks issue raised here.
I have WordPress installed in a subdirectory digitext-v1. Root directory only has phpinfo file.
root --> /var/www
subdirectory --> /var/www/digitext-v1
Plain permalinks work fine with home and all pages. Pretty permalinks work with home page but gives 404 error for all others.
My conf file is given below. Has almost identical setup (except for fqdn used in server name) to my live Nginx server where pretty permalinks work perfectly fine.
Can you help me resolve it before I lose my sanity? Anything to do with domain name? What am I doing wrong??
server {
listen 80;
server_name digitextv1 192.168.11.8;
root /var/www/digitext-v1;
index index.php index.html index.htm;
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location / {
# Setting pretty permalinks in WordPress
# First attempt to serve request as file ($uri)
# or directory ($uri/).
try_files $uri $uri/ /index.php?$args;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
EDIT (few lines from error log)
2021/08/31 16:05:48 [error] 3185#3185: *1406 FastCGI sent in stderr: "PHP message: PHP Warning: preg_match() expects parameter 2 to be string, array given in /var/www/digitext-v1/wp-content/plugins/popup-maker/includes/functions/popups/template.php on line 106PHP message: PHP Warning: preg_match() expects parameter 2 to be string, array given in /var/www/digitext-v1/wp-content/plugins/popup-maker/includes/functions/popups/template.php on line 106" while reading upstream, client: 192.168.11.41, server: 192.168.11.8, request: "GET /digitext-v1/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.11.8", referrer: "http://192.168.11.8/digitext-v1/wp-admin/options-permalink.php"
2021/08/31 16:06:28 [error] 3185#3185: *1426 FastCGI sent in stderr: "PHP message: PHP Warning: preg_match() expects parameter 2 to be string, array given in /var/www/digitext-v1/wp-content/plugins/popup-maker/includes/functions/popups/template.php on line 106" while reading upstream, client: 192.168.11.41, server: 192.168.11.8, request: "GET /digitext-v1/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.11.8"
2021/08/31 16:06:28 [error] 3185#3185: *1426 FastCGI sent in stderr: "PHP message: PHP Warning: preg_match() expects parameter 2 to be string, array given in /var/www/digitext-v1/wp-content/plugins/popup-maker/includes/functions/popups/template.php on line 106PHP message: PHP Warning: preg_match() expects parameter 2 to be string, array given in /var/www/digitext-v1/wp-content/plugins/popup-maker/includes/functions/popups/template.php on line 106" while reading upstream, client: 192.168.11.41, server: 192.168.11.8, request: "GET /digitext-v1/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.11.8"
2021/08/31 16:09:59 [error] 3185#3185: *1438 FastCGI sent in stderr: "PHP message: PHP Warning: preg_match() expects parameter 2 to be string, array given in /var/www/digitext-v1/wp-content/plugins/popup-maker/includes/functions/popups/template.php on line 106" while reading upstream, client: 192.168.11.41, server: 192.168.11.8, request: "GET /digitext-v1/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.11.8", referrer: "http://192.168.11.8/digitext-v1/wp-admin/options-permalink.php"
2021/08/31 16:09:59 [error] 3185#3185: *1438 FastCGI sent in stderr: "PHP message: PHP Warning: preg_match() expects parameter 2 to be string, array given in /var/www/digitext-v1/wp-content/plugins/popup-maker/includes/functions/popups/template.php on line 106PHP message: PHP Warning: preg_match() expects parameter 2 to be string, array given in /var/www/digitext-v1/wp-content/plugins/popup-maker/includes/functions/popups/template.php on line 106" while reading upstream, client: 192.168.11.41, server: 192.168.11.8, request: "GET /digitext-v1/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.11.8", referrer: "http://192.168.11.8/digitext-v1/wp-admin/options-permalink.php"
I had exactly the same issue this week. I even went so far as to reset WordPress, without success. I uploaded my .htacess file to my host advisor Chris at easy.dns and after some back and forth he deleted the following code to solve the problem:
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
<Files *config.json*>
order allow,deny
deny from all
</Files>

How to configure nginx proxy?

Here is what I need,
when its localhost:80 I need Nginx welcome page to be served, but when its localhost:80/pass, my application(react app) to be served, here is my Nginx.conf looks like,
server {
listen 80;
server_name localhost;
location /pass {
root build;
index index.html index.htm;
proxy_pass http://localhost:3000;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
am I missing something, because it's serving me this
An error occurred.
Sorry, the page you are looking for is currently unavailable.
Please try again later.If you are the system administrator of this resource then you should check the error log for details.Faithfully yours, nginx.
here is my error.log
2020/09/19 21:54:00 [error] 10888#1388: *35 connect() failed (10061: No connection could be made because the target machine actively refused it) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /pass HTTP/1.1", upstream: "http://[::1]:3000/", host: "localhost"
2020/09/19 21:54:39 [error] 10888#1388: *35 connect() failed (10061: No connection could be made because the target machine actively refused it) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /pass HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "localhost"

Nginx custom 404 page fails when in a higher directory

I am trying to create a custom 404 page with Nginx. My nginx.conf file looks like this:
http {
server {
location / {
root /nginx/html;
}
error_page 404 /custom_404.html;
location = /custom_404.html {
root /nginx/html;
internal;
}
}
}
When I check with a URL like "/page_that_doesnt_exist", it works fine.
But if I add a trailing "/", eg "/page_that_doesnt_exist/" or "/page_that_doesnt_exist/and_more_stuff" it fails, returning a blank screen (not the default nginx 404 page).
When I check the server messages, it tells me the following:
"GET /page_that_doesnt_exist/ HTTP/1.1" 404 280 "-"
[error] 6#6: *3 open() "/nginx/html/page_that_doesnt_exist/error404.js" failed (2: No such file or directory), client: 172.17.0.1, server: , request: "GET /page_that_doesnt_exist/error404.js HTTP/1.1", host: "localhost:8080", referrer: "http://localhost:8080/page_that_doesnt_exist/"
"GET /page_that_doesnt_exist/error404.js HTTP/1.1" 404 280 "http://localhost:8080/page_that_doesnt_exist/"
Which I take to mean that instead of nginx searching for my "custom_404.html" file in my "nginx/html" folder, it is adding "page_that_doesnt_exist" to the directory. Thus it now searches in "nginx/html/page_that_doesnt_exist/" and doesn't find a "custom_404.html" file in that directory.
What am I doing wrong here?

How to configure Location directive for different context URI

what is happening:
Im using following nginx.conf file for load balancing. web application is up and running on nginx 8080 port and able to access the landing page. however, when moving from landing page to "signup" page, it is throwing error.
what is expected:
nginx load balancer should redirect the load to the page as mentioned in the Location directive. but that is not happening.
nginx file :
events {
}
http {
upstream 3.121.253.126 {
server 3.121.253.126:8080;
server 3.121.253.126:8080;
server 3.121.253.126:8080;
}
error_log /etc/nginx/error_log.log warn;
client_max_body_size 20m;
proxy_cache_path /etc/nginx/cache keys_zone=one:500m max_size=1000m;
server {
listen 8080;
server_name 3.121.253.126;
root /etc/nginx/html;
index index.html;
location /signup {
root /etc/nginx/html;
index add-user.html;
# proxy_pass http://localhost:8080/signup;
# proxy_set_header Host $host;
# rewrite ^/welcome(.*)$ $1 break;
}
}
}
here is the error log:
2019/02/21 09:07:42 [error] 6#6: *510 recv() failed (104: Connection
reset by peer) while reading response header from upstream, client:
127.0.0.1, server: 3.121.253.126, request: "GET /signup HTTP/1.0", upstream: "http://127.0.0.1:8080/signup", host: "localhost:8080",
referrer: "http://3.121.253.126:8080/" 2019/02/21 09:07:42 [warn] 6#6:
*510 upstream server temporarily disabled while reading response header from upstream, client: 127.0.0.1, server: 3.121.253.126,
request: "GET /signup HTTP/1.0", upstream:
"http://127.0.0.1:8080/signup", host: "localhost:8080", referrer:
"http://3.121.253.126:8080/" 2019/02/21 09:13:10 [error] 6#6: *1
open() "/etc/nginx/html/signup" failed (2: No such file or directory),
client: 157.33.175.127, server: 3.121.253.126, request: "GET /signup
HTTP/1.1", host: "3.121.253.126:8080", referrer:
"http://3.121.253.126:8080/" 2019/02/21 09:15:57 [error] 6#6: *3
open() "/etc/nginx/html/signup" failed (2: No such file or directory),
client: 157.33.175.127, server: 3.121.253.126, request: "GET /signup
HTTP/1.1", host: "3.121.253.126:8080", referrer:
"http://3.121.253.126:8080/"
as per log, it is expecting signup html file. however, i am instructing it to use the add-user.html file. not sure why this is not happening.
please suggest
You want to point the URI /signup to the file located at /etc/nginx/html/add-user.html
There are a number of ways to achieve that using Nginx, including the rewrite and try_files directives.
For example:
location /signup {
try_files /add-user.html =404;
}
The root directive does not need to be repeated within this location block, as it will inherit the same value from the surrounding block.
The =404 does nothing as add-user.html always exists, but try_files requires two parameters. See this document for details.
The above location will process any request that begins with /signup (e.g. /signup/ or /signups).
To restrict it to the single URI /signup use the = modifier. See this document for details.
For example:
location = /signup {
try_files /add-user.html =404;
}

nginx - exclude all but two files

I need to allow the internet access to 2 files on my Nginx 1.6.0 web server:
[www.example.com/piwik.php][1]
[www.example.com/piwik.js][2]
Everything else needs to be blocked. What is the correct location directive to use? I have the below and it is only partially working:
# allow everyone to access piwik.php
location ~ /piwik.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# allow everyone to access piwik.js
location ~ /piwik.js$ {
root html;
index index.html index.htm;
}
# The below appears to allow index.php to load, but blocks
# files beneath it (e.g. js/file1.js, imgs/pic1.jpg) so the page
# is only half-rendered and I see a bunch of 403's in my NGINX logs.
# People are still able to access the half-loaded index.php webform
# and login!!!
location / {
allow 192.168.1.1
deny all;
root html;
index index.php index.html index.htm;
}
Access Log below:
1.2.3.4 - - [04/May/2014:20:04:22 -0400] "GET
/libs/jquery/stylesheets/jquery.smartbanner.css?cb=ef21e462d0300ea546811bec0ee6a912
HTTP/1.1" 403 162 "https://example.com/index.php" "Mozilla/5.0 (iPhone; CPU iPhone OS
7_1_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D201
Safari/9537.53"
1.2.3.4 - - [04/May/2014:20:04:22 -0400] "GET /plugins/Login/stylesheets/login.css?
cb=ef21e462d0300ea546811bec0ee6a912 HTTP/1.1" 403 162 "https://example.com/index.php"
"Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML,
like Gecko) Version/7.0 Mobile/11D201 Safari/9537.53"
1.2.3.4 - - [04/May/2014:20:03:15 -0400] "GET /plugins/Morpheus/images/logo.svg
HTTP/1.1" 403 162 "https://example.com/index.php" "Mozilla/5.0 (iPhone; CPU iPhone OS
7_1_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D201
Safari/9537.53"
The errors look like the below when users try to access the main page (index.php).
2014/05/06 14:17:51 [error] 6917#0: *385 access forbidden by rule, client: 180.76.X.X, server: example.com, request: "GET /robots.txt HTTP/1.1", host: "example.com"
2014/05/06 15:21:47 [error] 6917#0: *392 access forbidden by rule, client: 66.249.X.X, server: example.com, request: "GET / HTTP/1.1", host: "example.com"
2014/05/06 15:38:24 [error] 6917#0: *398 access forbidden by rule, client: 66.249.X.X, server: example.com, request: "GET / HTTP/1.1", host: "example.com"
2014/05/06 19:02:45 [error] 6917#0: *412 access forbidden by rule, client: 66.249.X.X, server: example.com, request: "GET / HTTP/1.1", host: "example.com"
2014/05/06 20:06:04 [error] 6917#0: *413 access forbidden by rule, client: 185.4.X.X, server: example.com, request: "GET http://24x7-allrequestsallowed.com/?PHPSESSID=1rmsxtj500143PRTJWQAY%40D%5EJFSX HTTP/1.1", host: "24x7-allrequestsallowed.com"
2014/05/06 20:09:22 [error] 6917#0: *414 access forbidden by rule, client: 66.249.X.X, server: example.com, request: "GET / HTTP/1.1", host: "example.com"

Resources