Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
ngxtop - real-time metrics for nginx server (and others)

ngxtop parses your nginx access log and outputs useful, top-like, metrics of your nginx server. So you can tell what is happening with your server in real-time. ngxtop tries to determine the correct location and format of nginx access log file by default, so you can just run ngxtop and having a close look at all requests coming to your nginx server. But it does not limit you to nginx and the default top view. ngxtop is flexible enough for you to configure and change most of its behaviours. You can query for different things, specify your log and format, even parse remote Apache common access log with ease. See sample usages below for some ideas about what you can do with it.


Installation:

pip install ngxtop


It is easy as pie, you just need to run it and look at the results:

nxtop

It will reports for total requests served and total bytes sent to client and will report requests based on their status code. At the pictures in the next post you can see sample usages.

#linux #nginx #top #nxtop #web_server
In case you want to serve static files in your website in nginX, you can add a new location directive to your server block that corresponds to your website:

server {

# your rest of codes in server block...

location / {

location ~ \.(css|ico|jpg|png) {
root /etc/nginx/www/your_site/statics;
}

# your rest of codes...

}
}

This is it, whether it is a uwsgi proxy, fpm, etc.

#web_server #nginx #static #location #serve
When you redirect in nginX you would use one of 302, 301 code like the below code:

location = /singup {
return 302 https://docs.google.com/forms;
}


But there is tiny tip here that needs to be told. If you want to pass parameter to the destination link, which in here is https:// docs.google.com/forms it wont work. String parameters are being held in $args varaible in nginX so you need to pass this variable like the following code:

location = /singup {
return 302 https://docs.google.com/forms$is_args$args;
}

The variable $is_args value will be set to "?" if a request line has arguments, or an empty string otherwise.


#nginx #web_server #redirect #302 #is_args #args
nginX by default does not set CORS headers for requests with error status codes like 401. There are 2 options here to add CORS headers:

1- If your nginX version is new you have the option of always to add to add_header:
add_header 'Access-Control-Allow-Origin' $http_origin always;

2- If you got error of invalid number of arguments in "add_header" directive, then use more_set_headers:
more_set_headers -s '401 400 403 404 500' 'Access-Control-Allow-Origin: $http_origin';

NOTE: when this error happens then in $.ajax or any similar method you wont have access to status codes. So be extremely catious!!!

#nginX #web_server #CORS #more_set_headers #add_header #ajax