Nginx (“engine x”) is a high performance HTTP and reverse proxy server and an IMAP/POP3/SMTP
proxy server. Nginx is the second most visited Rambler.ru in Russia by Igor Sysoev
Developed by the site, the first public version 0.1.0 was released on October 4, 2004. It releases its source code under a BSD-like license and is known for its stability, rich feature set, sample configuration files, and low system resource consumption. June 1, 2011, nginx
1.0.4 released.
If you use Debian or its derivatives, you can use sudo apt-get install
nginx to install and use nginx.
In this case, the configure options installed by default are as follows:
‘?conf-path=/etc/nginx/nginx.conf’, #configuration file path, the default is conf/nginx
‘?error-log-path=/var/log/nginx/error.log’,
#Error log path, the default is /logs/error.log
‘?http-client-body-temp-path=/var/lib/nginx/body’,
#Specify the path of the http client request cache file storage directory
‘?http-fastcgi-temp-path=/var/lib/nginx/fastcgi’, #Specify http
The path of the FastCGI cache file storage directory
‘?http-log-path=/var/log/nginx/access.log’, #Specify the path of http default access log
‘?http-proxy-temp-path=/var/lib/nginx/proxy’,
#Specify the http reverse proxy cache file storage directory
‘?http-scgi-temp-path=/var/lib/nginx/scgi’, #Specify http
The path of the sigi cache file storage directory
‘?http-uwsgi-temp-path=/var/lib/nginx/uwsgi’, #Specify http
The path of uwsgi cache file storage directory
‘?lock-path=/var/lock/nginx.lock’, # specify the path of the nginx.lock file
‘?pid-path=/var/run/nginx.pid’, #
Specify the path of the nginx.pid file, the default is /logs/nginx.pid
‘?with-debug’, #Enable debug logging
‘?with-http_addition_module’, #Enable http_addition_module
‘?with-http_dav_module’, #Enable http_dav_module
‘?with-http_geoip_module’,
‘?with-http_gzip_static_module’,
‘?with-http_image_filter_module’,
‘?with-http_realip_module’,
‘?with-http_stub_status_module’,
‘?with-http_ssl_module’,
‘?with-http_sub_module’,
‘?with-http_xslt_module’,
‘?with-ipv6’,
‘?with-sha1=/usr/include/openssl’,
‘?with-md5=/usr/include/openssl’,
‘?with-mail’,
‘?with-mail_ssl_module’,
‘?add-module=/build/buildd/nginx-0.8.54/debian/modules/nginx-upstream-fair’
After the installation is complete, the directory used by Nginx is as follows
/usr/sbin/nginx
/usr/share/nginx
/usr/share/doc/nginx
/etc/nginx
/etc/init.d/nginx
/etc/default/nginx
/etc/logrotate.d/nginx
/etc/ufw/applications.d/nginx
/var/lib/nginx
/var/lib/update-rc.d/nginx
/var/log/nginx
Website files can be placed under /usr/share/nginx/www.
If you are familiar with the Linux operating system, you can configure various operating environments in our VPS by yourself. The following takes Debian5 as an example to illustrate how to install and configure Nginx.
1. Download Nginx
wget http://3a88.googlecode.com/files/nginx_0.7.61-3_i386.deb
2. Install dependent packages
If you are doing a new installation, you may lack or need a higher version of libpcre3, just download it directly.
wget http://3a88.googlecode.com/files/libpcre3_7.8-3_i386.deb
3. Install Nginx
dpkg -ing nginx_0.7.61-3_i386.deb
4. Create a default site directory
The default site directory of nginx is /var/www/nginx-default This place
Let’s create this directory:
mkdir -p /var/www/nginx-default
We create a default homepage file index.html, which can be created with vim. Here we use the simplest echo command to create a
echo ‘All is OK!’ > /var/www/nginx-default/index.html
5. Start Nginx
/etc/init.d/nginx start
6. Test
Enter the IP address of the server in your browser, and it will be normal if you can see the following page
Update time: 2010-3-22
Debian configuration PHP5-FPM
After installing php-fpm, Nginx can perfectly support PHP. The installation method is very simple, as follows:
1. Modify /etc/apt/sources.list
Add the following sources into it, or just need the following two sources
deb http://packages.dotdeb.org stable all
deb-src http://packages.dotdeb.org stable alldeb
http://php53.dotdeb.org stable all
deb-src http://php53.dotdeb.org stable all
After joining, run apt-get update to update it
2. Start to install php5-fpm
apt-get install php5-fpm
3. Start php5-fpm
/etc/init.d/php5-fpm start
4. Modify the configuration file of Nginx
Modify /etc/nginx/sites-enabled/default Modify the following part, and comment out the comments.
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_param SCRIPT_FILENAME
/var/www/nginx-default/$fastcgi_script_name;
include fastcgi_params;
}
5. Reload the nginx configuration file
/etc/init.d/nginx reload
Use nginx to configure mirror server (CDN load balancing) under debian
It is estimated to use unstable as a living? The environment will not be very many-, ? Even this kind of bt…
After updating to the 2.6.30 kernel, you can start installing and configuring nginx…
# apt-get install nginx
Because the server is in the United States, the speed is fast…
I like to use emacs, I don’t use vim for now… As for what to use? I can solve it myself…
# emacs /etc/nginx/nginx.conf
Modify the content of http {}…
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
gzip_disable “MSIE [1-6]\.(?!.*SV1)”;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Save and exit…
# emacs /etc/nginx/sites-available/default
If you don’t need domain name binding, you don’t need to specify server_name
server {
listen 80;
#server_name The domain name to be bound, no need http://;
access_log /var/log/nginx/localhost.access.log;
location / {
proxy_pass http://domain name to be mirrored;
include /etc/nginx/proxy.conf;
#root /var/www/nginx-default; #Comment out
#index index.html index.htm; #comment out
}
}
Save and exit, then start creating proxy.conf file
# emacs /etc/nginx/proxy.conf
Write these things:
proxy_redirect off;
#proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 30;
proxy_send_timeout 30;
proxy_read_timeout 30;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
If the domain name is not bound to the mirrored host, you do not need to set the Host, you need to comment it out, otherwise…
If you have set it up and want to use something like dz, it is best to turn on this option…
After everything is set, you can test the configuration script…
# nginx -t
the configuration file /etc/nginx/nginx.conf syntax is ok
configuration file /etc/nginx/nginx.conf test is successful
If the prompt is successful, you can ⒍? ginx…
# /etc/init.d/nginx start
If it is normal, you can visit…
=. = The above configuration is complete…