這邊有個不錯的編譯安裝的步驟,來記錄一下
1、安裝預處理環境
[root@localhost ~]# dnf install -y lrzsz psmisc lsof wget ntpdate gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel net-tools iotop bc zip unzip zlib-devel nfs-utils automake libxml2 libxml2-devel libxslt libxslt-devel perl perl-ExtUtils-Embed gd-devel GeoIP GeoIP-devel
2、下載包並解壓
wget -O /usr/local/nginx-1.16.1.tar.gz http://nginx.org/download/nginx-1.16.1.tar.gz
tar xf /usr/local/nginx-1.16.1.tar.gz -C /usr/local
3、編譯選項
cd nginx-1.16.1
./configure --prefix=/usr/local/nginx --with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_image_filter_module \
--with-http_geoip_module \
--with-http_gunzip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module
4、編譯及安裝
[root@localhost nginx-1.16.1]# make && make install #創建目錄,並將生成的模塊和文件件復制到相應的目錄:
5、添加nginx用戶
[root@master2 nginx-1.16.1]# useradd nginx -s /sbin/nologin -u 2000 #以普通用戶啟動nginx
[root@master2 nginx-1.16.1]# chown nginx.nginx -R /usr/local/nginx #授權
nginx安裝完畢之后,在/usr/local/nginx
目錄下面能夠看到幾個目錄
[root@master2 nginx-1.16.1]# cd /usr/local/nginx
[root@master2 nginx]# ls
conf html logs sbin
conf:該目錄中保存了nginx所有的配置文件,其中nginx.conf是nginx服務器的最核⼼最主要的配置文件,其他的.conf則是用來配置nginx相關的功能的,例如fastcgi功能使用的是fastcgi.conf和fastcgi_params兩個文件,配置文件一般都有個樣板配置文件,是文件名.default結尾,使用時將其復制為並將default去掉即可。
html:該目錄中保存了nginx服務器的web文件,但是可以更改為其他目錄保存web文件,另外還有一個50x的web文件是默認的錯誤頁面提示頁面。
logs:該目錄用來保存nginx服務器的訪問日志錯誤日志等日志,logs目錄可以放在其他路徑,比如/var/logs/nginx里面。
sbin:該目錄用來保存nginx二進制啟動腳本,可以接受不同的參數以實現不同的功能。
6、驗證版本
[root@master2 nginx]# sbin/nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_image_filter_module --with-http_geoip_module --with-http_gunzip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
7、啟動nginx並訪問
[root@master2 nginx]# sbin/nginx
一些排錯問題
這是后續慢慢自己總結的一些。
1、今天遇到一個學員的問題。在執行make install 的時候,報了錯誤,詳細的錯誤是Error: mkdir: cannot create directory ‘/srv/nginx --with-file-aio File name too long
就是這種類似的,這是在make install 階段。一般來說,make install階段出現問題主要有權限問題,比如使用普通用戶進行make install可能寫不進去prefix指定的目錄,改成使用root用戶就可以了。但是這次不一樣,報的錯誤是不能創建目錄,其實在make install階段報錯只是把問題表現出來了,實際上configure階段就有問題了,只是沒有明顯的錯誤,執行echo $?你會發現也是顯示結果為0,表示成功。經過后續的仔細研究,發現在configure的命令中出現了可疑字符問題。如下所示:
[root@localhost nginx-1.16.1]# cat -A a.sh
./configure \$
--prefix=/srv/nginxM-BM- \$
--with-file-aioM-BM- \$
--with-http_auth_request_moduleM-BM- \$
--with-http_ssl_module \$
--with-http_addition_moduleM-BM- \$
--with-http_xslt_module=dynamicM-BM- \$
--with-http_geoip_module=dynamicM-BM- \$
也就是里面的M-BM-
字符,這種字符會導致我們命令直接不可用,但是看不到的,只能使用cat -A把所有的字符都顯示出來才行。所以我們要去掉,很簡單,如下命令所示:
sed -i 's/\xc2\xa0/ /g' a.sh
這樣就可以去掉特殊字符了、