Nginx安裝?開箱即用?

官網(wǎng)

http://nginx.org/
下載:http://nginx.org/download/

Nginx版本類型

Nginx官網(wǎng)提供了三個類型的版本
Mainline version:Mainline是Nginx目前主力在做的版本,開發(fā)版
Stable version:最新穩(wěn)定版,生產(chǎn)環(huán)境上建議使用的版本
Legacy versions:遺留的老的穩(wěn)定版
我們安裝的時候注意在官網(wǎng)選擇安裝Stable的版本
這里我們選擇的是nginx-1.12.2

環(huán)境

CentOS 6.5 x64
#設(shè)置hostname
master 192.168.40.130

安裝方式

源碼編譯安裝

安裝依賴類庫

c++ nginx的編譯依賴
prce 重定向支持
openssl https支持

]# yum install gcc-c++
]# yum -y install pcre*
]# yum -y install openssl*

查看依賴類庫安裝情況

]# rpm -qa  gcc-c++
gcc-c++-4.4.7-18.el6_9.2.x86_64

]# rpm -qa  pcre*
pcre-static-7.8-7.el6.x86_64
pcre-7.8-7.el6.x86_64
pcre-devel-7.8-7.el6.x86_64

]# rpm -qa  openssl*
openssl098e-0.9.8e-20.el6.centos.1.x86_64
openssl-perl-1.0.1e-57.el6.x86_64
openssl-1.0.1e-57.el6.x86_64
openssl-devel-1.0.1e-57.el6.x86_64
openssl-static-1.0.1e-57.el6.x86_64

安裝nginx

]# wget http://nginx.org/download/nginx-1.12.2.tar.gz
]# tar -xzvf nginx-1.12.2.tar.gz 
]# cd nginx-1.12.2
#設(shè)置安裝目錄為 /usr/local/src/nginx 
#設(shè)置支持https
]# ./configure --prefix=/usr/local/src/nginx --with-http_ssl_module
./configure

執(zhí)行./configure *** 命令后終端上會有些輸出
輸出的信息里會包含依賴的組件是否完整,如果不完整則需要另行安裝
輸出的信息里會包含配置文件目錄信息,日志文件目錄信息等一些很重要的我們做運維依賴的信息

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

  nginx path prefix: "/usr/local/src/nginx"
  nginx binary file: "/usr/local/src/nginx/sbin/nginx"
  nginx modules path: "/usr/local/src/nginx/modules"
  nginx configuration prefix: "/usr/local/src/nginx/conf"
  nginx configuration file: "/usr/local/src/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/src/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/src/nginx/logs/error.log"
  nginx http access log file: "/usr/local/src/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"
make
]# make
#省略若干行
sed -e "s|%%PREFIX%%|/usr/local/src/nginx|" \
        -e "s|%%PID_PATH%%|/usr/local/src/nginx/logs/nginx.pid|" \
        -e "s|%%CONF_PATH%%|/usr/local/src/nginx/conf/nginx.conf|" \
        -e "s|%%ERROR_LOG_PATH%%|/usr/local/src/nginx/logs/error.log|" \
        < man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/soft/nginx-1.12.2'
make install
]# make install

配置環(huán)境變量
]# vim /etc/profile

#set nginx environment
export NGINX_HOME=/usr/local/src/nginx
export PATH=${NGINX_HOME}/sbin:$PATH

]# source /etc/profile
nginx 命令行
]# nginx -h
nginx version: nginx/1.12.2
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /usr/local/src/nginx/)
  -c filename   : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file
  • 啟動 nginx
]# nginx
]# nginx -s reload
]# nginx -s stop
  • 重啟 nginx
]# nginx -s reload
  • 關(guān)閉 nginx
]# nginx -s stop

或者 查進程號之后 kill -9 pid

nginx 安裝驗證
  • 驗證nginx進程
]# ps -ef | grep nginx
root      1253     1  0 10:54 ?        00:00:00 nginx: master process ./nginx
nobody    1254  1253  0 10:54 ?        00:00:00 nginx: worker process
root      1267 56707  0 10:54 pts/4    00:00:00 grep nginx

可以看到nginx的master和worker進程

  • 驗證nginx默認(rèn)頁面

啟動nginx后可以通過主機名或者ip進行訪問驗證
http://master/
http://192.168.40.130/


看到以上頁面則證明nginx安裝成功

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容