This article mainly introduces the Python Flask framework and Nginx's static file access restriction function. Nginx uses its own XSendfile. For more information, see
Nginx configuration
Ngnix, a high-performance web server, is undoubtedly the current darling. Superior performance, flexible scalability, attacking the city and fighting the world in the server fie
Use Python to analyze Nginx access logs, split the logs according to the Nginx log format, and store them to the MySQL database.I. Nginx access log format:Copy codeThe Code is as follows:$ Remote_addr-$ remote_user [$ time_local]
Python Flask framework and Nginx implement static file access restrictions,
Nginx Configuration
Ngnix, a high-performance web server, is undoubtedly the current darling. Superior performance, flexible scalability, attacking the city and fighting the world in the server field.
Static files are an indispensable part of most websites. It is also common to use
Tutorial on configuring Nginx + Gunicorn + Python + Flask environment on CentOS, centosng.pdf
Basic Python Environment ConstructionPython 2.6 is installed by default in CENTOS 6.X series. Currently, Python 2.7 is mainly used in development. There are still many differences between the two versions, and the program is o
We need to learn a lot about Python programming in detail. Next, let's take a look at how to learn relevant technical information. I hope you will be helpful. First, confirm that the header file for Python programming is available (/usr/include/Python2.5)
If no sudo apt-get install Python2.5-dev
1. Nginx Installation
$./configure--add-module=/path/to/mod_wsg
background and hits the log to the specified log file or UDP server (daemonize uwsgi). In fact, the most common thing is to output the running record to a local file.pidfile : Specifies the location of the PID file and records the PID number of the main process.Vacuum : Automatically cleans up the environment when the server exits, removes UNIX socket files and PID files (try to remove all of the generated
I have encountered a requirement in my recent work to analyze nginx access logs and find it appropriate to use python. Therefore, the following article mainly introduces how to analyze nginx access logs using python regular expressions, for more information, see the following.
Preface
The script in this article analyz
The Nginx access log format is as follows:
The code is as follows
Copy Code
#使用的nginx默认日志格式 $remote _addr-$remote _user [$time _local] "$request $status $body _bytes_sent" $http _referer "" $http User_agent "" $http _x_forwarded_for "'
The Nginx access
script can be analyzed, because the log analysis on the application server native, so the performance and efficiency of the script must be guaranteed, can not affect the business
Again the principle:It is simpler to use Python's re module to analyze and process logs through regular expressions to obtain,,,,,,,, and uri args 时间当前 状态码 响应大小 响应时间 用户IP CDN ip server name etc. information stored in the database.Of course, the prerequisite specificatio
Use Python to parse Nginx access logs, split them according to the Nginx log format, and store them in the MySQL database.One, Nginx access log format is as follows:
Copy Code code as follows:
$remote _addr-$remote
: This article mainly introduces how to count the ip traffic of the client based on nginx access logs in python. if you are interested in the PHP Tutorial, refer to it. Professional statistical websites, such as Baidu Statistics, Google Analytics, and cnzz, provide common statistical indicators for webmasters, such as uv, pv, online duration, and ip address, in addition, due to network reasons, I found that
First look at the code:Nginx log monitoring script Python#! /Usr/bin/python2.6# Coding = UTF-8Import OSImport time# LoggingNum_file = '/data/www/www.111cn.net/log/num'Log_file = '/data/www/www.111cn.net/log/www.111cn.net.log'# Ip shield functionDef shellcmd (ip, con ):OS. system ('/root/shell/
If you want to see how many IP accesses Nginx has, which countries visit, and show the attribution of IP address distribution, Python can use the GAO Chunhui teacher ipip.net "Free IP Address Database", the shell can use Nali, I mainly use the Python language to implement the requirements, and send the query results as mail, but also to learn and review the
There are many such configurations on the Internet, but there is no one to rely on, a great effort to complete the architecture deployment. Record it by the way.I. Pre-Deployment NotesAfter installing the Python,django,uwsgi,nginx software first. After the configuration runs the software is in order. The first one. The Django project is well-configured/Opt/Web/testsite/directories and files The second one
In PHP, deployment is the most convenient. You only need to drop the PHP file to a path that supports PHP, and then access the path to use it. No matter how many PHP applications are added to the host, as long as you change the directory, no matter how php-cgi runs, deployment is extremely convenient.
On the other hand, Python is really a headache. Common deployment methods include:
◆ Fcgi: Use the spawn-fcgi or tool provided by the Framework to gener
, the environment is basically deployed, the dual WebSocket client connected to the WebSocket serverThe above script Specifies the R_log = "/tmp/web_socket.log" Log path, we need to generate this log file, and continue to write to the log in order to display the effect in the browser in real time (real scene, you can specify a server
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.