[nginx]linux nginx 安裝
linux nginx 安裝
作者:flymaster
qq:908601287
blog:http://www.cnblogs.com/flymaster500/
1.第一種安裝:編譯安裝
編譯安裝NGINX
1. 檢視安裝系統環境
[[email protected] ~]# cat /etc/redhat-release
CentOS release 6.7 (Final)
[[email protected] ~]# uname -r
2.6.32-573.el6.x86_64
[[email protected] ~]# uname -m
x86_64
2. ?採用yum安裝方式安裝pcre庫(rewrite模組所需)
[
[[email protected] ~]# rpm -qa pcre pcre-devel
pcre-7.8-7.el6.x86_64
pcre-devel-7.8-7.el6.x86_64
3. 採用yum安裝方式安裝Nginx基礎依賴包openssl、openssl-devel包
[[email protected] ~]# yum install openssl openssl-devel -y
[[email protected] ~]# rpm -qa penssl openssl-devel
openssl-devel-1.0.1e-48.el6_8.1.x86_64
openssl-1.0.1e-48.el6_8.1.x86_64
4.建立下載目錄存放軟體並安裝
[[email protected] ~]# mkdir -p /tools
#下載安裝包路徑
[[email protected] nginx-1.6.3]# mkdir -p /application
#軟體安裝路徑
[[email protected] ~]# cd /tools
[[email protected] tools]# wget -q http://nginx.org/download/nginx-1.6.3.tar.gz
[[email protected] tools]# ls -l nginx-1.6.3.tar.gz?
-rw-r--r-- 1 root root 805253 Apr ? ?015 nginx-1.6.3.tar.gz
[
[[email protected] tools]# cd nginx-1.6.3
安裝編譯引數
[[email protected] nginx-1.6.3]# ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.6.3/ --with-http_stub_status_module --with-http_ssl_module
[[email protected] nginx-1.6.3]# make && make install
[[email protected] nginx-1.6.3]# ln -s /application/nginx-1.6.3/ ?application/nginx
#建立軟連線便於後續軟體版本升級
5.檢查語法並啟動Nginx,chakan nginx對應服務的埠是否啟動成功
[[email protected] tools]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx-1.6.3//conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.6.3//conf/nginx.conf test is successful
[[email protected] tools]# lsof -i:80
COMMAND 燩ID 燯SER ?FD ?TYPE DEVICE SIZE/OFF NODE NAME
nginx ?1435 爎oot ??u 營Pv4 ?0146 ???t0 燭CP *:http (LISTEN)
nginx ?1438 nginx ??u 營Pv4 ?0146 ???t0 燭CP *:http (LISTEN)
或者
[[email protected] tools]# netstat -lnt|grep 80
tcp ???? ??? 0.0.0.0:80 ?????????.0.0.0:* ?????????LISTEN 牋
[[email protected] tools]# netstat -lntup|grep nginx
tcp ???? ??? 0.0.0.0:80 ?????????.0.0.0:* ?????????LISTEN ???456/nginx
[[email protected] tools]# ps -ef|grep nginx
root ???456 ??1 ? 14:03 ? ????0:00:00 nginx: master process /application/nginx/sbin/nginx
nginx ??4457 ?456 ? 14:03 ? ????0:00:00 nginx: worker process ????
root ???475 ?347 ? 14:12 pts/0 ??0:00:00 grep nginx
6. 檢查Nginx啟動實際效果,windows下瀏覽器輸入IP地址,Linux下可以使用wget 127.0.0.1或者curl 127.0.0.1
? ??????????牋
小技能:
1.使用./configure --help檢視幫助,編譯引數詳解:
./configure?
--user=nginx ????????????????牋#設定程序使用者許可權
--group=nginx ???????????????牋#設定程序使用者組許可權
--prefix=/application/nginx-1.6.3/ ??設定安裝路徑
--with-http_stub_status_module ??啟用狀態資訊
--with-http_ssl_module ?????????啟用ssl功能
2.檢視伺服器安裝nginx編譯時的引數(引數大寫V)
[[email protected] tools]# /application/nginx/sbin/nginx -V
nginx version: nginx/1.6.3
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)?
TLS SNI support enabled
configure arguments: --user=nginx --group=nginx --prefix=/application/nginx-1.6.3/ --with-http_stub_status_module --with-http_ssl_module
3.檢視nginx.pid程序號並查殺
[[email protected] tools]# cat /application/nginx/logs/nginx.pid?
[[email protected] tools]#kill -HUP `cat /application/nginx/logs/nginx.pid`
錯誤例項:
1. Nginx服務無法啟動,並出現如下提示
[[email protected] tools]# /application/nginx/sbin/nginx?
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
解決辦法:
[[email protected] tools]# killall -9 nginx
2.無法正常啟動nginx服務,提示nginx: [emerg] getpwnam("nginx") failed
? 牋?牋[[email protected] tools]# /application/nginx/sbin/nginx
? ???nginx: [emerg] getpwnam("nginx") failed
解決辦法:
[[email protected] tools]# useradd nginx -s /sbin/nologin -M
3.編譯安裝pcre,gcc不全導致報錯(yum安裝不存在此錯誤)
[[email protected] nginx-1.6.3]# make && make install
make all-am
make【1】: entering directory .....
cxx pcrecpp.lo
libtool:complie:unrecongnized option '-DHAVE_CONFIG_H'
...........
解決辦法:
執行“ yum install gcc-c++” 命令安裝gcc-c++依賴包
4.瀏覽器無法訪問nginx頁面
[[email protected] nginx-1.6.3]# /etc/init.d/iptables stop
[[email protected] nginx-1.6.3]# chkconfig iptables off
[[email protected] nginx-1.6.3]# setenforce 0 ?#臨時關閉
[[email protected] nginx-1.6.3]# vim /etc/selinux/config ?更改後重啟永久關閉
常用編譯引數選項說明
nginx大部分常用模組,編譯時./configure --help以--without開頭的都預設安裝。
--prefix=PATH : 指定nginx的安裝目錄。預設 /usr/local/nginx
--conf-path=PATH : 設定nginx.conf配置檔案的路徑。nginx允許使用不同的配置檔案啟動,通過命令列中的-c選項。預設為prefix/conf/nginx.conf
--user=name: 設定nginx工作程序的使用者。安裝完成後,可以隨時在nginx.conf配置檔案更改user指令。預設的使用者名稱是nobody。--group=name類似
--with-pcre : 設定PCRE庫的原始碼路徑,如果已通過yum方式安裝,使用--with-pcre自動找到庫檔案。使用--with-pcre=PATH時,需要從PCRE網站下載pcre庫的原始碼(版本4.4 - 8.30)並解壓,剩下的就交給Nginx的./configure和make來完成。perl正則表示式使用在location指令和 ngx_http_rewrite_module模組中。
--with-zlib=PATH : 指定 zlib(版本1.1.3 - 1.2.5)的原始碼解壓目錄。在預設就啟用的網路傳輸壓縮模組ngx_http_gzip_module時需要使用zlib 。
--with-http_ssl_module : 使用https協議模組。預設情況下,該模組沒有被構建。前提是openssl與openssl-devel已安裝
--with-http_stub_status_module : 用來監控 Nginx 的當前狀態
--with-http_realip_module : 通過這個模組允許我們改變客戶端請求頭中客戶端IP地址值(例如X-Real-IP 或 X-Forwarded-For),意義在於能夠使得後臺伺服器記錄原始客戶端的IP地址
--add-module=PATH : 新增第三方外部模組,如nginx-sticky-module-ng或快取模組。每次新增新的模組都要重新編譯(Tengine可以在新加入module時無需重新編譯)
參考閱讀
牋?牋https://segmentfault.com/a/1190000002797601
第二種安裝方式;yum 安裝
###安裝pcre
rpm -qa pcre pcre-devel
yum install -y pcre-devel
###安裝openssl-devel
rpm -qa openssl-devel openssl
####安裝nginx
wget http://nginx.org/download/nginx-1.6.3.tar.gz
./configure --prefix=/application/nginx-1.6.3 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module
useradd nginx -s /sbin/nologin -M
make && make install
作者:flymaster
qq:908601287
blog:http://www.cnblogs.com/flymaster500/