Linux下安裝設定nginx詳解

高洛峰
發布: 2023-03-05 14:42:01
原創
3666 人瀏覽過

一、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= 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= 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詳解

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!