1.安裝基礎環境包(如果已安裝,可更新) yum -y :自動選擇y
yum -y install openssl* yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel yum -y install libxml2 libxml2-devel zlib zlib-devel ncurses ncurses-devel curl curl-devel yum -y install gd gd2 gd-devel gd2-devel yum –y install gcc gcc-c++ gdb
注:本人在安裝過程發生一個錯誤,提示
/var/run/yum.pid 已被鎖定,PID 為 xxxx 的另一個程序正在運行
該解決辦法:直接在終端運行 rm -f /var/run/yum.pid 將該文件刪除,然后再次運行yum。
2. 安裝 pcre
1 ) 使用rz命令從主機下載pcre-8.38.zip文件(前提是主機上有該文件)
2) 解壓pcre-8.38.zip
unzip pcre-8.38.zip
3)安裝
cd pcre-8.38 ./configure make make install
3. 下載Nginx1.9.9 ,解壓安裝 (注:本人習慣將下載位置放於/tmp 下)
wget http://nginx.org/download/nginx-1.9.9.tar.gz tar -zxvf nginx-1.9.9.tar.gz cd nginx-1.9.9
/usr/sbin/groupadd www /usr/sbin/useradd -g www www
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/application/pcre
#注: 由於安裝pcre沒有指定目錄,因此不用指定--with-pcre。若安裝pcre有指定路徑,--with-pcre也要指定路徑
make
make install
4. 配置Nginx
cd /usr/local/nginx/conf -> vim nginx.conf user www www; worker_processes auto; worker_rlimit_nofile 204800; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; error_log /data/logs/nginx_error/nginx_error.log crit; #自己手動建立該路徑 pid logs/nginx.pid; events { use epoll; # Linux best model worker_connections 2048000; # max thread erery process multi_accept on; } http { #close the nginx version server_tokens off; sendfile on; tcp_nopush on; tcp_nodelay on; include mime.types; default_type application/octet-stream; charset UTF-8; # ssi on; # ssi_silent_errors on; # ssi_types text/shtml; #log_format main '$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 main; keepalive_timeout 65; client_header_timeout 10; client_body_timeout 10; reset_timedout_connection on; send_timeout 10; limit_conn_zone $binary_remote_addr zone=addr:5m; limit_conn addr 100; client_header_buffer_size 32k; large_client_header_buffers 4 4k; server_names_hash_bucket_size 128; client_max_body_size 100M; 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 256k; gzip on; gzip_disable "MSIE [1-6]\."; gzip_proxied expired no-cache no-store private auth; gzip_min_length 1k; gzip_comp_level 4; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; server { listen 80; server_name _; return 500; } include vhosts/*.conf; } mkdir vhosts chmod 777 vhosts
附 : 一些nginx有關基本命令
-> /usr/local/nginx/sbin/nginx 啟動
-> /usr/local/nginx/sbin/nginx -t 測試配置文件
-> /usr/local/nginx/sbin/nginx -s reload 重啟
-> /usr/local/nginx/sbin/nginx -v 查看nginx版本
-> /usr/local/nginx/sbin/nginx -V 查看nginx版本,及配置信息
-> netstat -antlp | grep 80 nginx占用80端口,檢查是否啟動
-> ps -ef | grep nginx 命令ps查找nginx的主進程號,檢查是否啟動(假設主進程號為3514)
-> kill -QUIT 3514 從容停止
-> kill -TERM 3514 快速停止
-> kill -9 3514 強制停止,只關閉一個主進程號,其余進程號仍在運行
-> kill -9 3514 3515 3525 強制關閉nginx所有進程號
-> kill -HUP 3514 平滑重啟