I have ajax site and static version of it in folder:
/_escaped_fragment_/
My config, doesn't working:
# nginx configuration
location / {
if ($query_string ~ "^_escaped_fragment_=$"){
rewrite ^(.*)$ /_escaped_fragment_$1/index.html? break;
}
if ($query_string ~ "^_escaped_fragment_=(.*)$"){
rewrite ^(.*)$ /_escaped_fragment_$1/%1/index.html? break;
}
}
Google bot request:
"GET /?_escaped_fragment_=/page/nerjav HTTP/1.1" 404 232 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
I just need to turn:
/#!/page/nerjav -> /_escaped_fragment_/page/nerjav/index.html
Error log:
2014/04/24 16:43:14 [error] 6087#0: *1 rewrite or internal redirection cycle while processing "/_escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment_//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html", client: 66.249.66.194, server: m-chel.ru, request: "GET /?_escaped_fragment_=/page/nerjav HTTP/1.1", host: "site.com"
2014/04/24 16:43:56 [error] 6087#0: *2 rewrite or internal redirection cycle while processing "/_escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment__escaped_fragment_//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html//page/nerjav/index.html", client: 109.191.139.106, server: m-chel.ru, request: "GET /?_escaped_fragment_=/page/nerjav HTTP/1.1", host: "site.com"
I'm not sure how your thing works, but it looks like you're missing an =.
# nginx configuration
location / {
if ($query_string ~ "^_escaped_fragment_=$"){
rewrite ^(.*)$ /_escaped_fragment_=$1/index.html? break;
}
if ($query_string ~ "^_escaped_fragment_=(.*)$"){
rewrite ^(.*)$ /_escaped_fragment_=$1/%1/index.html? break;
}
}
Related
I wrote this /etc/nginx/conf.d/apply.conf and started nginx.
server {
location = /hoge {
return 200;
}
}
but the curl command fails.
curl localhost:80/hoge
It says
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.13.9</center>
</body>
</html>
and the logs are
open() "/usr/share/nginx/html/hoge" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /hoge HTTP/1.1", host: "localhost"
I want to just return the status code without response body or with response body blank.
I changed to this but still not working.
location /hoge {
return 200 'Wow';
add_header Content-Type text/plain;
}
also tried this.
location /hoge {
return 200 'Wow';
default_type text/plain;
}
It is hard to say without context(how your entire nginx config file looks like), because of how nginx processes a request
A config file like the following, should work just fine for what you are looking for:
server {
listen 80;
location /hoge {
return 200;
}
}
However, if your config file has other location blocks(especially if they are regex based) then you may not get the expected solution.
Take an example of this config file:
server {
listen 80;
location /hoge {
return 200;
}
location ~* /ho {
return 418;
}
}
Sending a request to curl localhost:80/hoge would return a http status code 418 instead of 200. This is because the regex location matched before the exact location.
So, the long answer is; it is hard to tell without the context of the whole nginx conf file that you are using. But understanding how nginx processes a request will get you to the answer.
I wish my xmlrpc.php only accessible by wordpress-jetpack and thrown 404 to anyone else
I tried
location ~ /xmlrpc.php {
if ($http_user_agent !~* ".*jetpack.*") {
return 403;
}
}
I still get error when try connect my site from wordpress.com
2017/04/16 09:28:39 [error] 24200#24200: *1453 access forbidden by rule, client: 162.158.69.63, server: example.com, request: "POST /xmlrpc.php?for=jetpack&token=4xm%28
how do I create a redirect rules if $request_uri not contain "jetpack" then return 404 ?
I guess you just make a small, hm.. let's call it typo. You are using $http_user_agent in an attempt to check User Agent, but what you need to use is $request_uri or (as you specially ask for ) $query_string.
So Conf for xmlrpc location will work perfectly fine here.
location ~ /xmlrpc.php {
if ( $query_string !~* ".*jetpack.*" ) {
return 404;
}
}
I have the following structure I am working with for NGINX
/etc/nginx
- nginx.conf
- conf.d
- a.conf-disabled (I appended 'disabled' so it wont be used)
- b.conf-disabled (I appended 'disabled' so it wont be used)
- sites-available
- a
- b
- sites-enabled
- a (sym link to sites-available/a)
- b (sym link to sites-available/b)
The nginx.conf file looks like the following:
worker_processes 4;
events {
worker_connections 1024;
}
http {
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
The a file in sites-available looks like the following:
server {
listen 80;
server_name a;
location /a/ {
proxy_pass http://172.17.0.20:5678/;
}
}
and the b file in sites-available looks like the following:
server {
listen 80;
server_name b;
location /b/ {
proxy_pass http://172.17.0.20:5678/;
}
}
I am aware these pointing at the same address, I am just using it because I want to be able to test /a and /b separately.
The problem I am having is that only /a will work and /b fails. If I remove a, then /b works fine.
For example:
curl -X GET http://container-ip/a/ -> WORKS FINE
curl -X GET http://container-ip/b/ -> DOESN'T WORK
I ran logs and its not complaining about anything, but does fail with this when I try to hit /b.
2015/07/13 04:51:59 [error] 235#235: *58 "/etc/nginx/html/b/index.html" is not found (2: No such file or directory), client: 10.0.2.2, server: , request: "GET /b/ HTTP/1.1", host: "localhost:8181"
I have a transparent proxy server running on port 8008, I want to send some $uri to this proxy. This is what I have in the proxy server:
server
{
listen 8008;
location / {
resolver 8.8.8.8;
proxy_pass http://$http_host$request_uri;
}
access_log /var/log/nginx/proxy_access.log;
}
This actually works - if I put my host:8008 in any of my browser setting, proxy_access.log will show records like:
myb.row.ser.ip - - [12/Feb/2014:20:09:24 -0600] "GET http://col.stb01.s-msn.com/i/4B/7CC71C50462D34411C88C3623A69A.jpg HTTP/1.1" 200 9075 "http://www.msn.com/" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"
Please note the `"GET http://col.stb01..." portion.
Under one of my virtual server, I setup for a location (sample uri: /www.patterns.com/cat/subcat/sample.html):
location ~* (patterns)
{
set $hostx "";
set $addrs "";
if ( $uri ~ "^/(.*?)(/.*)$") {
set $hostx $1; # could be www.patterns.com
set $addrs $2; # could be /cat/subcat/sample.html
}
proxy_pass http://127.0.0.1:8008/http://$hostx$addrs;
proxy_set_header referer "";
}
The above code does send the captured uri to my proxy server, however what the proxy server sees is different, from the proxy_access.log:
127.0.0.1 - - [12/Feb/2014:20:44:28 -0600] "GET /http://www.patterns.com/cat/subcat/sample.html HTTP/1.0" 502 574 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36"
Please note the leading slash in: "GET /http://www.patterns.co...", I believe that causes the proxy server to return the 502 code.
Now my question is: in my location, how do I send the correct uri to the proxy server?
Thanks,
you should remove the "/http://" part in your proxy_pass.
Actually, I don't really understand why you need to get $hostx and $addrs, check nginx doc
While passing request nginx replaces URI part which corresponds to location with one indicated in proxy_pass directive. But there are two exceptions from this rule when it is not possible to determine what to replace:
if the location is given by regular expression;
if inside proxied location URI is changed by rewrite directive, and this configuration will be used to process request (break):
location /name/ {
rewrite /name/([^/] +) /users?name=$1 break;
proxy_pass http://127.0.0.1;
}
For these cases of URI it is transferred without the mapping.
How can I completely disable logging from HttpLimitConnModule and HttpLimitReqModule?
At least limit the damage done from extensive logging in case of a DOS-attack. I still want some error-logging but not when the request is denied.
Such messages:
2013/07/12 20:20:10 [error] 31544#0: *78 limiting requests, excess: 0.519 by zone "limit", client: *.*.*.*, server: example.com, request: "GET /static.html HTTP/1.1", host: "example.com", referrer: ""
One solution is to enable error_log just where it is needed.
server {
error_log /dev/null crit;
location ~\.php$ {
error_log /var/log/nginx_error.log;
}
}