部署高性能Web服务器 – 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
./配置 \
–用户=nginx \ # user is nginx
–组=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
./配置 –救命
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”
使 & 进行安装
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
用户 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;
大事记
{
使用 epoll; # epoll module
worker_connections 51200; #maximum allowed connection of each process.
}
http
{
include mime.types;
default_type 应用程序/八位字节流;
#charset gb2312;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32ķ;
sendfile on;
tcp_nopush 开启;
keepalive_timeout 60;
tcp_nodelay 开启;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64ķ;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip 上;
gzip_min_length 1k;
gzip_buffers 4 16ķ;
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;
服务器
{
听 80;
server_name localhost; #hostname or server name
index index.html index.htm index.php; # default main page name.
根目录 /usr/local/nginx/html; #root directory in website
位置 / {
root html;
index index.html index.htm;
}
limit_conn crawler 20;
#FastCGI can support PHP
位置~ .*\.(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
位置~ .*\.(gif|jpg|JPEG格式|PNG|bmp|瑞士法郎|js|css)$
{
30天到期;
}
#日志格式
log_format access ‘$remote_addr – $远程用户 [$时间_本地] “$要求” ‘
'$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” $http_x_forwarded_for';
access_log logs/access.log access;
}
}
保存并退出!
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
聚苯乙烯 | grep nginx
netstat -nltp | 格雷普 80
links 127.0.0.1 # 如果 “welcome to nginx!” 出现了, this indicat nginx startup successfully
or you can input “本地主机” in url bar of web brower , if you have seen “welcome to nginx!”
It means that nginx starup successfully