一、環境
作業系統版本:CentOS Linux release 7.4.1708 (Core) 迷你安裝版 二、安裝過程
1、安裝編譯工具及相關庫。
[root@Geeklp-Nginx ~]# yum -y install gcc-c++ zlib-devel openssl-devel libtool
2、下載Nginx及PCRE。
[root@Geeklp-Nginx ~]# curl -C - -O http://mirrors.sohu.com/nginx/nginx-1.13.7.tar.gz[root@Geeklp-Nginx ~]# curl -C - -O https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz
3、編譯安裝PCRE。
[root@Geeklp-Nginx ~]# tar -xvzf pcre-8.41.tar.gz[root@Geeklp-Nginx pcre-8.41]# cd pcre-8.41[root@Geeklp-Nginx pcre-8.41]# mkdir /usr/local/share/applications/pcre-8.41[root@Geeklp-Nginx pcre-8.41]# ./configure --prefix=/usr/local/share/applications/pcre-8.41/[root@Geeklp-Nginx pcre-8.41]# make && make install
4、編譯安裝Nginx。
[root@Geeklp-Nginx ~]# tar -xvzf nginx-1.13.7.tar.gz[root@Geeklp-Nginx nginx-1.13.7]# cd nginx-1.13.7[root@Geeklp-Nginx nginx-1.13.7]# ./configure --prefix=/usr/local/share/applications/nginx-1.13.7/ --with-http_ssl_module[root@Geeklp-Nginx nginx-1.13.7]# make && make install
5、啟動Nginx。
[root@Geeklp-Nginx nginx-1.13.7]# /usr/local/share/applications/nginx-1.13.7/sbin/nginx
6、配置防火牆。
[root@Geeklp-Nginx nginx-1.13.7]# firewall-cmd --permanent --add-port=80/tcp[root@Geeklp-Nginx nginx-1.13.7]# firewall-cmd --reload
7、驗證。
在瀏覽器中輸入伺服器位址:10.1.1.21。出現如下圖所示則說明Nginx安裝成功。
三、配置Nginx
1、查看Nginx版本:
[root@Geeklp-Nginx nginx-1.13.7]# /usr/local/share/applications/nginx-1.13.7/sbin/nginx -vnginx version: nginx/1.13.7
2、修改設定檔,去掉以下幾行的注釋,此步驟主要用於測試組態檔案修改是否正確。
3、檢查配置是否正確。
[root@Geeklp-Nginx conf]# ../sbin/nginx -tnginx: the configuration file /usr/local/share/applications/nginx-1.13.7//conf/nginx.conf syntax is oknginx: configuration file /usr/local/share/applications/nginx-1.13.7//conf/nginx.conf test is successful
4、重載設定檔,配置防火牆。
[root@Geeklp-Nginx conf]# ../sbin/nginx -s reload[root@Geeklp-Nginx conf]# firewall-cmd --permanent --add-port=443/tcp[root@Geeklp-Nginx conf]# firewall-cmd --reload
5、驗證。在瀏覽器裡輸入https://10.1.1.21/
說明https配置已經生效,但是不能正常使用,如需正常使用還需進一步配置。此處暫不討論。
6、停止Nginx。
[root@Geeklp-Nginx conf]# ../sbin/nginx -s stop
7、啟動Nginx並再次重啟Nginx。
[root@Geeklp-Nginx conf]# ../sbin/nginx[root@Geeklp-Nginx conf]# ../sbin/nginx -s reopen
8、查看協助。
[root@Geeklp-Nginx conf]# ../sbin/nginx -hnginx version: nginx/1.13.7Usage: 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/share/applications/nginx-1.13.7//) -c filename : set configuration file (default: conf/nginx.conf) -g directives : set global directives out of configuration file
9、配置開機啟動。
[root@Geeklp-Nginx sbin] echo "/usr/local/share/applications/nginx-1.13.7/sbin/nginx">>/etc/rc.local[root@Geeklp-Nginx sbin]# chmod u+x /etc/rc.d/rc.local
其他內容後期文章再進一步討論。