deploy high performance web server – nginx
1、install basic independent packages
yum -y install gcc openssl-devel pcre-devel zlib-devel
2、deploy nginx
useradd nginx -s /sbin/nologin #add nginx user
tar zxvf nginx-1.2.7.tar.gz #uncompress nginx tar.gz package.
cd nginx-1.2.7
./configure \
–user=nginx \ # user is nginx
–group=nginx \ #user group is nginx
–prefix=/usr/local/nginx/ \ # nginx home path
–with-http_stub_status_module \
–with-http_ssl_module #ssl module
# for more parameter,you can refoer to this command
./configure –help
nginx path prefix: “/usr/local/nginx”
nginx binary file: “/usr/local/nginx/sbin/nginx”
nginx configuration prefix: “/usr/local/nginx/conf”
nginx configuration file: “/usr/local/nginx/conf/nginx.conf”
nginx pid file: “/usr/local/nginx/logs/nginx.pid”
nginx error log file: “/usr/local/nginx/logs/error.log”
nginx http access log file: “/usr/local/nginx/logs/access.log”
nginx http client request body temporary files: “client_body_temp”
nginx http proxy temporary files: “proxy_temp”
nginx http fastcgi temporary files: “fastcgi_temp”
make & make install
check whether the configuration in nginx is correct or not
after installation.
/usr/local/nginx/sbin/nginx –v
3、configure nginx
cd /usr/local/nginx/conf/
rm -rf nginx.conf
vim nginx.conf
paste the following configuration to nginx.conf
user nginx nginx; #user and user group
worker_processes 8; #process amount when nginx start
error_log logs/nginx_error.log crit; #error log and log level
pid /usr/local/nginx/nginx.pid; #PID file path
worker_rlimit_nofile 51200;
events
{
use epoll; # epoll module
worker_connections 51200; #maximum allowed connection of each process.
}
http
{
include mime.types;
default_type application/octet-stream;
#charset gb2312;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m;
server
{
listen 80;
server_name localhost; #hostname or server name
index index.html index.htm index.php; # default main page name.
root /usr/local/nginx/html; #root directory in website
location / {
root html;
index index.html index.htm;
}
limit_conn crawler 20;
#FastCGI can support PHP
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000; #fastcgi listen port 9000
fastcgi_index index.php;
include fcgi.conf; #fastcg configuration file.
}
#for a type of static file , you can set long cache time
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$
{
expires 30d;
}
#log format
log_format access ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” $http_x_forwarded_for’;
access_log logs/access.log access;
}
}
save and exit!
NOTE : this is a baisc confifguration file,you need to edit it again if you would like to
configure other featuer.
4、start nginx,and check the working status
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ps -ef | grep nginx
netstat -nltp | grep 80
links 127.0.0.1 # if “welcome to nginx!” appeared, this indicat nginx startup successfully
or you can input “localhost” in url bar of web brower , if you have seen “welcome to nginx!”
It means that nginx starup successfully