I. Install nginx download nginx source package, the official website is http://wiki.nginx.org/Main, in order to support gzip and regular expressions, you also need to download the PCRE and zlib source package. Pcre url: http://www.pcre.org/,zlib http://www.zlib.net /. The nginx version I downloaded is 1.4.1, the PCRE version is 8.32, And the zlib version is 1.2.8. After the download is complete, extract the three source code packages. Enter the nginx directory configuration. (Note: Install OpenSSL first if the system does not exist)
./configure --prefix=$HOME/nginx --with-openssl=/usr/include --with-pcre=../pcre-8.32 --with-http_stub_status_module --with-zlib=../zlib-1.2.8
For more information about nginx configuration options, see the official documentation. Gzip compression, regular expressions, and SSL are configured here. -- The with-http_stub_status_module is the module that installs to view nginx status.
Then
make && make install
After the installation is complete, you can set the configuration file. My configuration file is relatively simple and set as follows:
# User nobody; worker_processes 1; # error_log logs/error. log; # error_log logs/error. log notice; # error_log logs/error. log Info; # PID logs/nginx. PID; events {use epoll; worker_connections 1024;} HTTP {include mime. types; default_type application/octet-stream; # log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request"' # '$ Status $ response "$ http_referer"' # '"$ http_user_agent" "$ http_x_forwarded_for "'; # access_log logs/access. log main; sendfile on; # tcp_nopush on; # keepalive_timeout 0; keepalive_timeout 65; gzip on; # enable gzip compression # gzip_min_length 1 K; # minimum compression length, the size is less than this length and does not compress gzip_buffers 4 16 K; # the size of gzip compressed cache, which is set to 4 times of gzip_http_version 1.1 of 16 K; gzip_comp_level 2; # compression ratio gzip_types text/plain application/X-JavaScript text/CSS application/XML; gzip_vary on; server {Listen 8000; # listener port SERVER_NAME localhost; # charset koi8-r; # access_log logs/host. access. log main; Location/{root HTML; index index.html index.htm ;}Location/Py {include uwsgi_params; uwsgi_pass localhost: 8081 ;}# Error_page 404/404 .html; # redirect server error pages to the static page/50x.html # error_page 500 502 503 x.html; location =/50x.html {root HTML ;}}}After the configuration is complete, run $ nginx_path/sbin/nginx to start nginx. Note that the root permission is required to start the program, so you can use the sudo command, or change the nginx program owner to root, and then set the s flag.
sudo chown root:root nginxsudo chmod +s nginx
Close command:Nginx-s stopCommand for reloading the configuration file:Nginx-s reload
The rough section in the configuration file above is the uwsgi section I configured, that is, the path for/Py, all processed by the uwsgi program listening at localhost: 8081. Uwsgi installation is described in the second part.For details about gzip parameters, see http://blog.csdn.net/jessonlv/article/details/8016284. Check whether Gzip is enabled on the server. You can use the curl tool.
curl -I -H "Accept-Encoding: gzip, deflate" "http://localhost"
If Gzip is enabled, the server response should be similar to the following:
HTTP/1.1 200 OKServer: nginx/0.7.67Date: Mon, 20 May 2013 01:49:47 GMTContent-Type: text/htmlLast-Modified: Thu, 19 Jul 2012 03:16:40 GMTConnection: keep-aliveContent-Encoding: gzip
2. Install and download the uwsgi source code package at http://uwsgi-docs.readthedocs.org/en/latest /. Compile and install
make && make install
Configure uwsgi in nginx. The bold Section in the configuration file for nginx installation is the configuration section. Run the following command to start the instance.
uwsgi --socket localhost:8081 --wsgi-file wsgi.py --master --processes 4 --threads 2 --stats localhost:9191
Wsgi. py is my own Python program, as shown below:
def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return "Hello World"
Now you can use localhost: 8080/Py to access the program and output Hello world.