一、必要軟件準備
1.安裝pcre
為了支持rewrite功能,我們需要安裝pcre
代碼如下:# yum install pcre* //如過你已經裝了,請跳過這一步
2.安裝openssl
需要ssl的支持,如果不需要ssl支持,請跳過這一步
代碼如下:# yum install openssl*
3.gzip 類庫安裝
代碼如下:yum install zlib zlib-devel
4.安裝wget
下載nginx使用,如果已經安裝,跳過這一步
代碼如下:# yum install wget
二、安裝nginx
1.下載
代碼如下:wget http://nginx.org/download/nginx-1.7.0.tar.gz
2.解壓
代碼如下:
tar -zxvf nginx-1.7.0.tar.gz
3.編譯和安裝
執行如下命令:
代碼如下:
# cd nginx-1.7.0
# ./configure --prefix=/usr/local/nginx-1.7.0 /
--with-http_ssl_module --with-http_spdy_module /
--with-http_stub_status_module --with-pcre
–with-http_stub_status_module:支持nginx狀態查詢
–with-http_ssl_module:支持https
–with-http_spdy_module:支持google的spdy,想了解請百度spdy,這個必須有ssl的支持
–with-pcre:為了支持rewrite重寫功能,必須制定pcre
最后輸出如下內容,表示configure OK了。
代碼如下:
checking for zlib library ... found
creating objs/Makefile
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ md5: using OpenSSL library
+ sha1: using OpenSSL library
+ using system zlib library
nginx path prefix: "/usr/local/nginx-1.7.0"
nginx binary file: "/usr/local/nginx-1.7.0/sbin/nginx"
nginx configuration prefix: "/usr/local/nginx-1.7.0/conf"
nginx configuration file: "/usr/local/nginx-1.7.0/conf/nginx.conf"
nginx pid file: "/usr/local/nginx-1.7.0/logs/nginx.pid"
nginx error log file: "/usr/local/nginx-1.7.0/logs/error.log"
nginx http access log file: "/usr/local/nginx-1.7.0/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,如果沒有安裝請執行yum install make
# make install
三、啟動、關閉、重置nginx
啟動:直接執行以下命令,nginx就啟動了,不需要改任何配置文件,nginx配置多域名虛擬主機請參考后續文章.
代碼如下:/usr/local/nginx-1.7.0/sbin/nginx
試試訪問:直接使用curl命令來讀取web信息
代碼如下:
[root@ns conf]
# curl -s http://localhost | grep nginx.com
nginx.com.
關閉:
代碼如下:/usr/local/nginx-1.7.0/sbin/nginx -s stop
重置:當你有修改配置文件的時候,只需要reload以下即可
代碼如下:/usr/local/nginx-1.7.0/sbin/nginx -s reload
整個nginx的安裝就到這里結束了。
新聞熱點
疑難解答
圖片精選