Nginx安裝部署

Nginx依賴三個包

  1. gzip 模塊需要 zlib 庫 ( 下載: http://www.zlib.net/ )  zlib-1.2.8.tar.gz

wget http://zlib.net/zlib-1.2.8.tar.gz

tar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8

./configure

make&make install

2. rewrite 模塊需要 pcre 庫 ( 下載: http://www.pcre.org/ )  pcre-8.21.tar.gz

安裝PCRE庫

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.21.tar.gz

tar -zxvf pcre-8.21.tar.gz

cd pcre-8.21

./configure

make&make install

3. ssl 功能需要 openssl 庫 ( 下載: http://www.openssl.org/ )  openssl-1.0.1.tar.gz

wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz

tar -zxvf openssl-1.0.1c.tar.gz

./config

make&make install


注:可以使用一鍵安裝依賴包 yum -y groupinstall "Development Tools" "Development Libraries"

4.安裝nginx

wget http://nginx.org/download/nginx-1.2.8.tar.gz

tar -zxvf nginx-1.2.8.tar.gz

cd nginx-1.2.8  

./configure --prefix=/usr/local/nginx \
--conf-path=/etc/nginx/nginx.conf \
--sbin-path=/usr/sbin/nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_p_w_picpath_filter_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gzip_static_module \
--with-http_concat_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_sysguard_module \
--with-backtrace_module \
--with-http_stub_status_module \
--with-http_upstream_check_module

#定義編譯參數#

make&make install

5.編輯nginx.conf文件#需要根據具體情況編寫#

user www p2progs;
worker_processes 8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
pid /var/run/nginx.pid;
worker_rlimit_nofile 65536;
events
{
use epoll;
worker_connections 65536;
}
http
{
include mime.types;
default_type application/octet-stream;
charset utf-8;
server_names_hash_bucket_size 128;
client_header_buffer_size 4k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
open_file_cache max=65536 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 1;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
server_tokens off;
port_in_redirect off;
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_vary 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_disable "MSIE [1-6]\.(?!.*SV1)";
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
proxy_buffer_size 16k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
server

{
listen 80;
server_name #只需更改 server_name 爲對應的網站域名即可# 
index index.html index.htm;
error_log 
access_log 
if ($host ~* ^(p2puser.com)$) {
rewrite ^/(.*)$ 
break;
}
rewrite ^(.*)\;(.*)$ $1 last;
location ~ \.( jsp|do|html|action|tpl|eot|svg|page|woff|ttf)$ {
proxy_pass http://127.0.0.1:8564;
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;
}

}

}

6.nginx安裝完畢,啓動nginx。service nginx start(如果找不到命令,可能是nginx安裝版本的問題沒有啓動腳本。copy一個腳本過來,就可以使用命令了。當然還有別的命令進行重啓,開啓,關閉)。

7.chkconfig nginx on(將nginx添加到開機啓動,

 注:proxy_pass http://127.0.0.1:8564 要和 tomcat 端口保持一致。

8.nginx相關命令:

/usr/local/nginx/nginx -t 檢查nginx配置文件

/usr/local/nginx/nginx -s reload 重新加載配置文件(不停止服務)

/usr/local/nginx/sbin/nginx –s reload 重啓

9.Nginx編譯的參數

–prefix #nginx安裝目錄,默認在/usr/local/nginx
–pid-path #pid文件位置,默認在logs目錄
–lock-path #lock文件位置,默認在logs目錄
–with-http_ssl_module #開啓HTTP SSL模塊,以支持HTTPS請求。
–with-http_dav_module #開啓WebDAV擴展動作模塊,可爲文件和目錄指定權限
–with-http_flv_module #支持對FLV文件的拖動播放
–with-http_realip_module #支持顯示真實來源IP地址
–with-http_gzip_static_module #預壓縮文件傳前檢查,防止文件被重複壓縮
–with-http_stub_status_module #取得一些nginx的運行狀態
–with-mail #允許POP3/IMAP4/SMTP代理模塊
–with-mail_ssl_module #允許POP3/IMAP/SMTP可以使用SSL/TLS
–with-pcre=../pcre-8.21 #注意是未安裝的pcre路徑
–with-zlib=../zlib-1.2.8 #注意是未安裝的zlib路徑
–with-debug #允許調試日誌
–http-client-body-temp-path #客戶端請求臨時文件路徑
–http-proxy-temp-path #設置http proxy臨時文件路徑
–http-fastcgi-temp-path #設置http fastcgi臨時文件路徑
–http-uwsgi-temp-path=/var/tmp/nginx/uwsgi #設置uwsgi 臨時文件路徑

–http-scgi-temp-path=/var/tmp/nginx/scgi #設置scgi 臨時文件路徑


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章