編譯安裝 nginx -1.14.2
1 ) 下載nginx-1.14.2 源碼包:
wget http://nginx.org/download/nginx-1.14.2.tar.gz
2 ) 編譯安裝 nginx:
### 1 ) 安裝nginx 編譯的依賴包(基本需要這3類的devel包,其他缺少的包自行解決報錯):
yum install pcre pcre-devel openssl openssl-devel zlib zlib-devel -y
### 2 ) 解壓並安裝nginx(注意定制的安裝路徑根據自己的需求自行更改 ):
tar -zxvf nginx-1.14.2.tar.gz && cd nginx-1.14.2/
### 3 ) 編譯安裝nginx:
./configure --prefix=/data/nginx --http-client-body-temp-path=/data/nginx/cache/nginx/client_temp --http-proxy-temp-path=/data/nginx/cache/nginx/proxy_temp --http-fastcgi-temp-path=/data/nginx/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/data/nginx/cache/nginx/uwsgi_temp --http-scgi-temp-path=/data/nginx/cache/nginx/scgi_temp --user=fmw --group=fmw --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-pcre --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
make && make install
### 4 ) 添加環境變量到系統:
vim /etc/profile.d/nginx.sh
PATH=$PATH:/data/nginx/bin/:/data/nginx/sbin
export PATH
source /etc/profile
3 ) 添加啟動腳本(centos 7 ):
### 3.1 編寫nginx啟動腳本:
[root@localhost ~]# vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/data/nginx/sbin/nginx
ExecReload=/data/nginx/sbin/nginx -s reload
ExecStop=/data/nginx/sbin/nginx -s quit
PrivateTmp=true
#EnvironmentFile=/etc/sysconfig/rdisc
#ExecStart=/sbin/rdisc $RDISCOPTS
[Install]
WantedBy=multi-user.target
### 3.2 添加開啟啟動:
systemctl enable nginx
### 3.3 查看nginx服務狀態:
systemctl start nginx
systemctl status nginx
4 ) nginx 主要配置文件:
grep -vE '^#|^$|^ #' nginx.conf
user fmw fmw; # 運行nginx的用戶組和用戶.
worker_processes auto; # 使用的CPU內核.
error_log logs/error.log notice; # nginx 錯誤日志的存放路徑和日志級別.
pid logs/nginx.pid; # PID 路徑.
events {
use epoll; # 使用的網絡模型select,epoll,
worker_connections 65535;
}
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;
sendfile on;
tcp_nopush on;
keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name www.188faka.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.php index.html index.htm;
}
error_page 404 /404/404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
server {
listen 443 ssl;
server_name www.188faka.com;
ssl_certificate /data/nginx/conf/188kafa_ssl/188faka.crt;
ssl_certificate_key /data/nginx/conf/188kafa_ssl/188faka.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.php index.html index.htm;
}
error_page 404 /404/404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}