http://flowsnow.net/2017/03/30/CentOS7%E4%B8%8ANginx%E7%BC%96%E8%AF%91%E5%AE%89%E8%A3%85/
安裝編譯環(huán)境
yum -y install gcc automake autoconf libtool make
yum install gcc gcc-c++
安裝pcre
pcre(Perl Compatible Regular Expressions): perl 兼容的正則表達(dá)式庫奴饮。
以下各編譯安裝的源碼包均放在/usr/local/src下,Nginx依賴pcre是為了重寫rewrite供填。
從ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/下載pcre包拐云,不宜太新,推薦使用pcre8.39或8.40近她,太新的pcre版本Nginx不支持叉瘩。
cd /usr/local/src
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz
tar -zxvf pcre-8.39.tar.gz
cd pcre-8.39
./configure
make
make install
安裝zlib
zlib是為了Nginx壓縮
從http://zlib.net/出下載當(dāng)前最新源碼http://zlib.net/zlib-1.2.11.tar.gz
cd /usr/local/src
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
make install
安裝ssl
cd /usr/local/src
wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz
tar -zxvf openssl-1.0.1t.tar.gz
cd openssl-1.0.1t
./config # 不是./Configure
make
make install
安裝Nginx
Nginx 一般有兩個(gè)版本,分別是穩(wěn)定版和開發(fā)版粘捎,您可以根據(jù)您的目的來選擇這兩個(gè)版本的其中一個(gè)薇缅,下面是把 Nginx 安裝到 /usr/local/nginx 目錄下的詳細(xì)步驟:
cd /usr/local/src
wget http://nginx.org/download/nginx-1.10.2.tar.gz
tar -zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2
./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.39 --with-zlib=/usr/local/src/zlib-1.2.11 --with-openssl=/usr/local/src/openssl-1.0.1t --with-http_v2_module --with-ipv6
make
make install
--with-pcre=/usr/local/src/pcre-8.39 指的是pcre-8.39 的源碼路徑。
--with-zlib=/usr/local/src/zlib-1.2.11 指的是zlib-1.2.11 的源碼路徑攒磨。
--with-openssl=/usr/local/src/openssl-1.0.1t指的是openssl-1.0.1t 的源碼路徑泳桦。
--with-http_v2_module 啟用 https,時(shí)如需使用 http/2 協(xié)議,則會(huì)依賴ngx_http_v2_module模塊娩缰,可以使用--with-http_v2_module配置參數(shù)來啟用灸撰。
--with-ipv6 啟用IPV6
開機(jī)自啟動(dòng)nginx
http://www.reibang.com/p/b5fa86d54685
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/nginx -c /usr/local/nginx/nginx.conf
ExecReload=/usr/local/nginx/nginx -s reload
ExecStop=/usr/local/nginx/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl start nginx.service #啟動(dòng)nginx服務(wù)
systemctl status nginx.service #查看服務(wù)當(dāng)前狀態(tài)
systemctl restart nginx.service #重新啟動(dòng)服務(wù)
systemctl list-units --type=service #查看所有已啟動(dòng)的服務(wù)