本文檔以吉林考試項(xiàng)目為例,采用編譯方式來(lái)安裝部署nginx
nginx版本 | nginx源碼包存放錄 | nginx安裝目錄 | nginx存放代碼目錄 | nginx日志目錄 |
nginx-1.12.2 | nginx-1.12.2 | /usr/local/nginx | /home/yunwei/nginx-data | /home/yunwei/nginx-logs |
創(chuàng)建nginx源碼包存放目錄
mkdir /usr/local/src/nginx
下載nginx源碼包到指定目錄
wget http://nginx.org/download/nginx-1.12.2.tar.gz -P /usr/local/src/nginx/
解壓nginx源碼包
tar xf /usr/local/src/nginx/nginx-1.12.2.tar.gz -C /usr/local/src/nginx/
安裝依賴包
yum -y install pcre-devel openssl-devel
創(chuàng)建nginx用戶
useradd -s /sbin/nologin -M nginx
創(chuàng)建nginx安裝目錄
mkdir /usr/local/nginx
cd /usr/local/src/nginx/nginx-1.12.2/
./configure --prefix=/usr/local/nginx/ --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module
make && make install
ln -s /usr/local/nginx/sbin/nginx /sbin/nginx
mkdir /home/yunwei/nginx-data/jl_exam/jl_exam_poral/ROOT -p
mkdir /home/yunwei/nginx-data/jl_exam/jl_exam_manage_view/ROOT/ -p
mkdir /home/yunwei/nginx-logs/jl_exam/ -p
chmod 755 /home/yunwei/
chown -R nginx.nginx /home/yunwei/nginx-*
備份配置文件
cp /usr/local/nginx/conf/nginx.conf{,.ori}
創(chuàng)建虛擬主機(jī)配置文件存放目錄
mkdir /usr/local/nginx/conf/extra/jl_exam
cat >/usr/local/nginx/conf/nginx.conf <<EOF
worker_processes 1;
worker_rlimit_nofile 2048;
events {
worker_connections 4096;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
fastcgi_intercept_errors on;
send_timeout 15s;
server_tokens off;
client_max_body_size 50m; #客戶端可上傳的大報(bào)文(附件)大小為50MB,默認(rèn)為1MB
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/css text/xml application/javascripts;
gzip_vary on;
client_max_body_size 50m;
client_header_timeout 120s;
client_body_timeout 120s;
client_body_buffer_size 256k;
log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '
'\$status \$body_bytes_sent "\$http_referer" '
'"\$http_user_agent" "\$http_x_forwarded_for"';
include extra/jl_exam/jl_exam_poral.conf;
include extra/jl_exam/jl_exam_manage_view.conf;
}
EOF
vim /usr/local/nginx/conf/extra/jl_exam/jl_exam_manage_view.conf
server {
listen 8081;
server_name 10.0.0.14;
access_log /home/yunwei/nginx-logs/jl_exam/jl_exam_manage_view_access.log main;
error_log /home/yunwei/nginx-logs/jl_exam/jl_exam_manage_view_error.log;
location / {
root /home/yunwei/nginx-data/jl_exam/jl_exam_manage_view/ROOT;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
vim /usr/local/nginx/conf/extra/jl_exam/jl_exam_poral.conf
server {
listen 80;
server_name 10.0.0.14;
access_log /home/yunwei/nginx-logs/jl_exam/jl_exam_poral_access.log main;
error_log /home/yunwei/nginx-logs/jl_exam/jl_exam_poral_error.log;
location / {
root /home/yunwei/nginx-data/jl_exam/jl_exam_poral/ROOT;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
將代碼放入相應(yīng)的站點(diǎn)目錄里
nginx #啟動(dòng)nginx
echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.local #添加到開機(jī)自啟動(dòng)
利用系統(tǒng)自帶的logrotate進(jìn)行切割nginx日志文件
創(chuàng)建nginx_jl_exam文件
cat >/etc/logrotate.d/nginx_jl_exam <<EOF
/home/yunwei/nginx-logs/jl_exam/*.log{
daily
rotate 10
create
dateext
notifempty
postrotate
[ -f /usr/local/nginx/logs/nginx.pid ] && kill -USR1 \`cat /usr/local/nginx/logs/nginx.pid\`
endscript
}
EOF
強(qiáng)制執(zhí)行一次,切割日志,以后每天會(huì)定時(shí)切割日志
logrotate -f /etc/logrotate.d/nginx_jl_exam
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
分享題目:CentOS7.5中編譯安裝nginx-1.12.2-創(chuàng)新互聯(lián)
路徑分享:http://aaarwkj.com/article12/cccogc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、品牌網(wǎng)站制作、搜索引擎優(yōu)化、響應(yīng)式網(wǎng)站、自適應(yīng)網(wǎng)站、網(wǎng)站內(nèi)鏈
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容