編譯安裝nginx
1、安裝依賴庫
yum -y install pcre-devel //yum安裝依賴庫
編譯安裝:
yum groupinstall "Development Tools" //安裝編譯環境
tar jxvf pcre-8.00.tar.bz2 -C /usr/src/ //解壓依賴包
cd /usr/src/pcre-8.00/
./configure && make && make install //編譯安裝依賴包
2、編譯nginx
useradd -M -s /sbin/nologin nginx //建立程式運作使用者
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_gunzip_module --with-http_stub_status_module //配置
make && make install //編譯 安裝
3、nginx指令
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin //建立控制腳本
nginx: //啟動服務
-h //顯示幫助資訊
-v //顯示版本
-V //顯示編譯子產品
-t //測試配置檔案文法
-c //指定測試其他nginx的配置檔案
-s //運作控制
stop:關閉服務 quit:退出服務 reopen:重新開機 reload:重載
nginx常用編譯參數
基本參數:
--prefix //Nginx安裝的根路徑
--pid-path //nginx主程序pid寫入的檔案位置,通常在var/run下
--user //指定運作使用者
--group //指定運作組
--error-log-path //錯誤日志路徑
--http-log-path //通路日志路徑
子產品參數:
--with-http_stub_status_module //擷取nginx的運作狀态
--with-http_gunzip_module //對于不支援gzip編碼的客戶,該子產品用于為客戶解壓縮預壓縮内容
--with-http_image_filter_module //圖像過濾器(需要libgd庫)
--with-http_ssl_module //SSL加密子產品
--with-http_flv_module //支援對FLV檔案的拖動播放
--with-http_realip_module //顯示真實來源IP位址,主要用于NGINX做前端負載均衡伺服器使用,
--with-http_gzip_static_module //檢查是否用戶端已經存在以“.gz”結尾的壓縮檔案,防止檔案被重複壓縮
nginx配置執行個體:
user nginx;
worker_processes 4;
worker_rlimit_nofile 65535;
error_log logs/error.log info;
pid logs/nginx.pid;
events {
use epoll;
worker_connections 20480;
}
http {
include mime.types;
default_type application/octet-stream;
#定義日志格式和日志格式名
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; #通路日志路徑,調用main格式
sendfile on;
keepalive_timeout 120;
gzip on;
gzip_comp_level 9;
upstream name_back { #叢集配置
server 192.168.0.2;
server 192.168.0.3 weight=2;
server 192.168.0.4 weight=3;
server 192.168.0.5 backup;
}
server { #主機配置
listen 80;
server_name www.test.com; #域名
location / {
root html/test;
#proxy_pass http://name_back; #啟用叢集
index index.html index.php;
}
#錯誤頁面
error_page 404 /404.html;
location = /404.html {
root html;
#50x錯誤
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
#主機配置
server {
server_name www.nginx.com; #域名
root html/nginx;
#url重寫,将通路html目錄下的請求全部交給www.test.com處理
#rewrite ^/(.*)$ http://www.test.com/$1 redirect;
#ssl配置,需要ca證書,私有ca的搭建請參考我以前的部落格
listen 443;
server_name www.apache.com;
ssl_certificate ssl/cert.pem; #證書檔案
ssl_certificate_key ssl/cert.key; #秘鑰檔案位置
ssl_session_timeout 5m; #會話逾時時間
ssl_prefer_server_ciphers on; #啟用ssl
本文轉自 紅塵世間 51CTO部落格,原文連結:http://blog.51cto.com/hongchen99/1913339