I'm trying to build a location block that serves files from the /tmp directory, but only ones that do not end with a .txt extension.
For now I have this :
location ~^\/temporary(?!.*\.txt$)(.*)$ {
root /tmp;
try_files $1 =404;
}
The problem is I only get 404s, even though the file I'm asking for exists. I used a little debug to make sure of that, here's the debug dump for the "/temporary/test.html" URI:
022/07/17 19:53:42 [debug] 6408#0: *1 http script capture: "/test.html"
2022/07/17 19:53:42 [debug] 6408#0: *1 trying to use file: "/test.html" "/tmp/test.html"
2022/07/17 19:53:42 [debug] 6408#0: *1 trying to use file: "=404" "/tmp=404"
2022/07/17 19:53:42 [debug] 6408#0: *1 http finalize request: 404, "/temporary/test.html?" a:1, c:1
2022/07/17 19:53:42 [debug] 6408#0: *1 http special response: 404, "/temporary/test.html?"
2022/07/17 19:53:42 [debug] 6408#0: *1 http set discard body
2022/07/17 19:53:42 [debug] 6408#0: *1 HTTP/1.1 404 Not Found
As you can see the server actually tried to read the /tmp/test.html file, so the path crafting has worked.
Also the file exists and is readable as shown with this command :
sudo -u nobody stat /tmp/test.html
File: /tmp/test.html
Size: 15 Blocks: 8 IO Block: 4096 regular file
Device: 803h/2051d Inode: 2097220 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ nobody) Gid: ( 1000/ user)
Access: 2022-07-17 19:26:19.701542983 +0300
Modify: 2022-07-17 19:53:17.923305174 +0300
Change: 2022-07-17 19:53:17.923305174 +0300
Birth: 2022-07-17 19:26:19.701542983 +0300
What am I missing ?
Okay so apparently the /tmp directory was the origin of the problem. When I tried another directory everything worked as expected for some reason.
Related
I have no idea how to fix this...
2019/01/14 05:15:02 [alert] 27307#27307: *9 write() to "/var/log/nginx/access.log" failed (28: No space left on device) while logging request, client: 108.162.226.175, server: titomi.cf, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock", host: "titomi.cf"
2019/01/14 05:15:22 [error] 27307#27307: *11 FastCGI sent in stderr: "PHP message: PHP Warning: mysqli_connect(): (HY000/2002): No such file or directory in /var/www/test/lib/common.lib.php on line 1443" while reading response header from upstream, client: 162.158.118.78, server: test.titomi.cf, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "test.titomi.cf"
I think this is access.log error size
How can I reduce the size of access.log?
You probably need log rotation to rotate the logs.
sudo vim /etc/logrotate.d/nginx
/var/log/nginx/*.log {
daily
missingok
rotate 14
compress
notifempty
create 0640 www-data adm
}
Daily: Rotate the logs daily basis
missingok: Do not give output if log is missing
Rotate 14: Will keep the last 14 logs
Compress: Will the compress the old copies of the log files.
You can run the logrotate
logrotate /var/log/nginx/
2014/03/31 23:06:50 [error] 25914#0: *765 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 173.77.251.136, server: wiki.resonant-rise.com, request: "POST /index.php?title=Chisel&action=submit HTTP/1.1", upstream: "fastcgi://127.0.0.1:9016", host: "wiki.resonant-rise.com", referrer: "http://wiki.resonant-rise.com/index.php?title=Chisel&action=edit"
2014/03/31 23:06:50 [error] 25914#0: *765 open() "/usr/share/nginx/html/50x.html" failed (2: No such file or directory), client: 173.77.251.136, server: wiki.resonant-rise.com, request: "POST /index.php?title=Chisel&action=submit HTTP/1.1", upstream: "fastcgi://127.0.0.1:9016", host: "wiki.resonant-rise.com", referrer: "http://wiki.resonant-rise.com/index.php?title=Chisel&action=edit"
I have a mediawiki installation and an IPB installation. They both through up errors but this one error from mediawiki prevents me from posting semi-large articles. I have tried a lot of the solutions out there, adding catch_workers_output = yes, adjusting pm.* settings. Still not able to resolve this issue. I am coming to my wits end trying to figure this one out.
PHP-FPM Conf
http://pastie.org/private/aczklc52ll9yv0uz5drcqg
PHP-FPM WWW.CONF
http://pastie.org/private/wod3xipxhm8ractksw7ha
NGINX VHOST for MEDIAWIKI
http://pastie.org/private/h9co8aykbdmfzk2bd5qq
If the failure depends on size of the pages, it has to do with how much work the operation causes. My wild guess would be: increase the timeout (you currently have send_timeout 60s;).
It's easy for the parse time of a very long page to go over 60 seconds, especially if you're on a low power server, have not tuned performance or have enabled heavy parser extensions.
in my case it was that the php version of the project was different with the version of php I had been
Hello i installed symfony2 on my nginx web host but it densest show up the project I've done
http://www.instelamrketing.es its the website and i used this commands to configure the server
http://www.leaseweblabs.com/2013/05/symfony2-under-nginx-on-ubuntu-12-04/
here some error logs
tail -f logs/error_log
#4 /home/intelmarketing.es/public_html/app/cache/prod/classes.php(5519): Monolog\Logger->addRecord(500, 'Uncaught PHP Ex...', Array)
#5 /home/intelmarketing.es/public_html/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/ExceptionL in /home/intelmarketing.es/public_html/app/cache/prod/classes.php on line 5141" while reading response header from upstream, client: 180.211.176.176, server: intelmarketing.es, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9007", host: "www.intelmarketing.es"
2013/08/14 18:15:05 [error] 2583#0: *3 FastCGI sent in stderr: "PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'The stream or file "C:/wamp/www/symfony/app/logs/prod.log" could not be opened: failed to open stream: No such file or directory' in /home/intelmarketing.es/public_html/app/cache/prod/classes.php:5141
Stack trace:
#0 /home/intelmarketing.es/public_html/app/cache/prod/classes.php(5089): Monolog\Handler\StreamHandler->write(Array)
#1 /home/intelmarketing.es/public_html/app/cache/prod/classes.php(5018): Monolog\Handler\AbstractProcessingHandler->handle(Array)
#2 /home/intelmarketing.es/public_html/app/cache/prod/classes.php(5204): Monolog\Handler\AbstractHandler->handleBatch(Array)
#3 /home/intelmarketing.es/public_html/app/cache/prod/classes.php(5419): Monolog\Handler\FingersCrossedHandler->handle(Array)
#4 /home/intelmarketing.es/public_html/app/cache/prod/classes.php(5519): Monolog\Logger->addRecord(500, 'Uncaught PHP Ex...', Array)
#5 /home/intelmarketing.es/public_html/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/ExceptionL in /home/intelmarketing.es/public_html/app/cache/prod/classes.php on line 5141" while reading response header from upstream, client: 180.211.176.176, server: intelmarketing.es, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9007", host: "www.intelmarketing.es"
what might be the problem?
Thank you
/Aleksandar!
Clear your app/logs and app/cache directories and give your web server permissions to write to them (read the installation chapter). You left there some files from your development machine.
I have nginx 1.4.1 and unicorn set up on centos - I am getting a 502 Bad Gateway error and my nginx logs shows this:
1 connect() to unix:/tmp/unicorn.pantry.sock failed (2: No such file or directory)
while connecting to upstream, client: 192.168.1.192, server: , request: "GET / HTTP/1.1",
upstream: "http://unix:/tmp/unicorn.pantry.sock:/", host: "192.168.1.30"
There is no /tmp/unicorn.pantry.sock file or directory. I am thinking that it might be a permission error and therefore the file can't be written if so who requires what permission - I have also read that I can create a tcp client
Also I don't understand where the 192.168.1.192 comes from
I just want to make it work How can I do it?
Ok I figured this out. I had unicorn.sock in my shared directory so I needed to point unix: to it
I have my site which is using nginx, and testing site with header testing tools e.g. http://www.webconfs.com/http-header-check.php but every time it says 400 bad request below is the out put from the tool. Though all my pages load perfectly fine in browser and when I see in chrome console it says status code 200OK.
HTTP/1.1 400 Bad Request =>
Server => nginx
Date => Fri, 07 Sep 2012 09:40:09 GMT
Content-Type => text/html
Content-Length => 166
Connection => close
I really don't understand what is the problem with my server config?
A bit of googling suggests to increase the buffer size using, and I increased it to following:
large_client_header_buffers 4 16k;
The same results persist.
Can some one guide me to the right direction?
As stated by Maxim Dounin in the comments above:
When nginx returns 400 (Bad Request) it will log the reason into error
log, at "info" level. Hence an obvious way to find out what's going on
is to configure
error_log
to log messages at "info" level and take a look into error log when
testing.
Yes changing the error_to debug level as Emmanuel Joubaud suggested worked out (edit /etc/nginx/sites-enabled/default ):
error_log /var/log/nginx/error.log debug;
Then after restarting nginx I got in the error log with my Python application using uwsgi:
2017/02/08 22:32:24 [debug] 1322#1322: *1 connect to unix:///run/uwsgi/app/socket, fd:20 #2
2017/02/08 22:32:24 [debug] 1322#1322: *1 connected
2017/02/08 22:32:24 [debug] 1322#1322: *1 http upstream connect: 0
2017/02/08 22:32:24 [debug] 1322#1322: *1 posix_memalign: 0000560E1F25A2A0:128 #16
2017/02/08 22:32:24 [debug] 1322#1322: *1 http upstream send request
2017/02/08 22:32:24 [debug] 1322#1322: *1 http upstream send request body
2017/02/08 22:32:24 [debug] 1322#1322: *1 chain writer buf fl:0 s:454
2017/02/08 22:32:24 [debug] 1322#1322: *1 chain writer in: 0000560E1F2A0928
2017/02/08 22:32:24 [debug] 1322#1322: *1 writev: 454 of 454
2017/02/08 22:32:24 [debug] 1322#1322: *1 chain writer out: 0000000000000000
2017/02/08 22:32:24 [debug] 1322#1322: *1 event timer add: 20: 60000:1486593204249
2017/02/08 22:32:24 [debug] 1322#1322: *1 http finalize request: -4, "/?" a:1, c:2
2017/02/08 22:32:24 [debug] 1322#1322: *1 http request count:2 blk:0
2017/02/08 22:32:24 [debug] 1322#1322: *1 post event 0000560E1F2E5DE0
2017/02/08 22:32:24 [debug] 1322#1322: *1 post event 0000560E1F2E5E40
2017/02/08 22:32:24 [debug] 1322#1322: *1 delete posted event 0000560E1F2E5DE0
2017/02/08 22:32:24 [debug] 1322#1322: *1 http run request: "/?"
2017/02/08 22:32:24 [debug] 1322#1322: *1 http upstream check client, write event:1, "/"
2017/02/08 22:32:24 [debug] 1322#1322: *1 http upstream recv(): -1 (11: Resource temporarily unavailable)
Then I took a look to my uwsgi log and found out that:
Invalid HTTP_HOST header: 'www.mysite.local'. You may need to add u'www.mysite.local' to ALLOWED_HOSTS.
[pid: 10903|app: 0|req: 2/4] 192.168.221.2 () {38 vars in 450 bytes} [Wed Feb 8 22:32:24 2017] GET / => generated 54098 bytes in 55 msecs (HTTP/1.1 400) 4 headers in 135 bytes (1 switches on core 0)
And adding www.mysite.local to the settings.py ALLOWED_HOSTS fixed the
issue :)
ALLOWED_HOSTS = ['www.mysite.local']
I had the same issue and tried everything. This 400 happened for an upstream proxy.
Debug logged showed absolutely nothing.
The problem was in duplicate proxy_set_header Host $http_host directive, which I didn't notice initially.
Removing duplicate one solved the issue immediately.
I wish nginx was saying something other than 400 in this scenario, as nginx -t didn't complain at all.
P.S. this happened while migrating from older nginx 1.10 to the newer 1.19. Before it was tolerated apparently.
Just to clearify, in /etc/nginx/nginx.conf, you can put at the beginning of the file the line
error_log /var/log/nginx/error.log debug;
And then restart nginx:
sudo service nginx restart
That way you can detail what nginx is doing and why it is returning the status code 400.
A cause can be invalid encoding in the URL request. Such as % being passed un-encoded.
When nginx returns 400(bad request) it will log the reason into error log, at "info" level and take a look into error log when testing.
In my case, the issue was that port 443 wasn´t opened in the router
If you get log just like this:
client xx.xx.xx.xx closed keepalive connection
For this issue:"Connection: upgrade" causes 400 error that never reaches application code. Triggered by common nginx config. #17081
just set proxy_set_header Connection $http_connection
normally, Maxim Donnie's method can find the reason. But I encountered one 400 bad request will not log to err_log. I found the reason with the help with tcpdump