首頁  >  文章  >  後端開發  >  Linux下安裝設定nginx詳解

Linux下安裝設定nginx詳解

高洛峰
高洛峰原創
2017-02-07 16:52:263705瀏覽

一、Linux下安裝配置nginx

第一次安裝nginx,中間出現的問題一步步解決。 

使用的工具secureCRT,連線並登入伺服器。

1.1 rz指令,會彈出會話框,選擇要上傳的nginx壓縮包。

#rz

1.2 解壓縮

[root@vw010001135067 ~]# cd /usr/local/
[root@vw010001135067 local]# tar -zvxf nginx-1.10.2.tar.gz

1.3 進入nginx資料夾,執行./configure指令

[root@vw010001135067 local]# cd nginx-1.10.2
[root@vw010001135067 nginx-1.10.2]# ./configure

報錯誤如下:這個錯誤。那就是gcc 包沒有安裝。

1.3.1 安裝gcc

查看gcc

checking for OS
 + Linux 2.6.32-431.el6.x86_64 x86_64
checking for C compiler ... not found
 
./configure: error: C compiler cc is not found

安裝gcc

[root@vw010001135067 nginx-1.10.2]# whereis gcc
gcc:

安裝成功後再次查看了安裝gcc

[root@vw010001135067 nginx-1.10.2]# yum -y install gcc

安裝成功後再次查看包了。

1.3.2 繼續執行./configure

[root@vw010001135067 nginx-1.10.2]# whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/libexec/gcc /usr/share/man/man1/gcc.1.gz

出現如上錯誤。安裝pcre-devel

[root@vw010001135067 nginx-1.10.2]# ./configure
checking for OS
 + Linux 2.6.32-431.el6.x86_64 x86_64
checking for C compiler ... found
......
checking for PCRE library ... not found
checking for PCRE library in /usr/local/ ... not found
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found
 
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

1.3.3 再次執行./configure

[root@vw010001135067 nginx-1.10.2]# yum install pcre-devel

如果有這個錯誤那麼執行

error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.

1.3.4 執行

yum install zlib-devel

你想使用openssl 功能,sha1 功能。 那麼安裝openssl ,sha1 吧

[root@vw010001135067 nginx-1.10.2]# ./configure
checking for OS
 + Linux 2.6.32-431.el6.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC)
.......
Configuration summary
 + using system PCRE library
 + OpenSSL library is not used
 + md5: using system crypto library
 + sha1: using system crypto library
 + using system zlib library
 
 nginx path prefix: "/usr/local/nginx"
 nginx binary file: "/usr/local/nginx/sbin/nginx"
 nginx modules path: "/usr/local/nginx/modules"
 nginx configuration prefix: "/usr/local/nginx/conf"
 nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
 nginx pid file: "/usr/local/nginx/logs/nginx.pid"
 nginx error log file: "/usr/local/nginx/logs/error.log"
 nginx http access log file: "/usr/local/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"

1.4.1 開啟ssl 模組執行./configure –with-http_ssl_module

[root@vw010001135067 nginx-1.10.2]# yum install openssl openssl-devel
[root@vw010001135067 nginx-1.10.2]# install perl-Digest-SHA1.x86_64

1.4.2 啟用「server+servers」頁,執行「執行/configst」
[root@vw010001135067 nginx-1.10.2]# ./configure --with-http_ssl_module

上面兩個指令同時啟動可以

[root@vw010001135067 nginx-1.10.2]# ./configure --with-http_stub_status_module

1.5 上面configure就通過了

執行make 指令,執行make install 指令

[root@vw010001135067 nginx-1.10.2]# ./configure --with-http_stub_status_module --with-http_ssl_module

到此/etc/profile 中加入設定 

開啟設定檔

[root@vw010001135067 nginx-1.10.2]# make
[root@vw010001135067 nginx-1.10.2]# make install

在設定檔中加入

[root@vw010001135067 nginx-1.10.2]# vi /etc/profile

   


注意到上面我的nginx_home配置的位址不對。先找到nginx的安裝地址

#nginx configure
export NGINX_HOME=/usr/local/nginx-1.10.2
export PATH=$PATH:$NGINX_HOME/sbin

   

還真是地址寫錯了,把上面的改成

[root@vw010001135067 nginx-1.10.2]# whereis nginx
nginx: /usr/local/nginx

 使配置生效。

1.7 查看nginx版本

#nginx configure
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin

整個過程成功了!

二、修改nginx.conf

2.1 啟動nginx

我的nginx服務在http://10.1.135.67/,設定成功後,現在啟動nginx

[root@vw010001135067 nginx-1.10.2]# source /etc/profile

//10.1.135.67/,預設埠號80.


如上圖,nginx已經正常運作了。

2.2 設定tomcat服務

現在我的tomcat服務在10.1.29.15,需要透過nginx轉送。那麼打開nginx.conf,修改設定檔。如下,新增:

[root@vw010001135067 nginx]# nginx -v
nginx version: nginx/1.10.2

配置好後,儲存設定文件,並且重新啟動nginx

[root@vw010001135067 nginx]# cd /usr/local/nginx
[root@vw010001135067 nginx]# nginx -c conf/nginx.conf

在瀏覽器呼叫upload專案是否成功 

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持PHP中文網。

更多Linux下安裝設定nginx詳解相關文章請關注PHP中文網! Linux下安裝設定nginx詳解

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn