|
#安裝PCRE庫支持
- yum install pcre-devel pcre -y
複製代碼 #安裝wget
#下載Nginx源碼包- wget -c http://nginx.org/download/nginx-1.12.0.tar.gz
複製代碼 #解壓Nginx源碼包
- tar -xzf nginx-1.12.0.tar.gz
複製代碼 #進入解壓目錄,然後sed修改Nginx版本信息為JWS- sed -i -e 's/1.12.0//g' -e 's/nginx\//JWS/g' -e 's/"NGINX"/"JWS"/g' src/core/nginx.h
複製代碼 #預編譯Nginx
- ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
複製代碼 出現以下報錯:
checking for OS
+ Linux 3.10.0-327.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
解决方法:安装gcc
错误信息:
./configure: error: the HTTP rewrite module requires the PCRE library.
解决方法:安装pcre-devel
错误信息:
./configure: error: the HTTP gzip module requires the zlib library.
解决方法:安装zlib-devel
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
解决方法:
执行以下命令:
- yum -y install openssl openssl-devel
複製代碼
#.configure預編譯成功後,執行make命令進行編譯
#make執行成功後,執行make install 正式安裝
#至此Nginx Web服務器安裝完畢
測試Nginx服務安裝是否正確,同時啟動Nginx Web服務,具體步驟如下:
1.檢查Nginx配置文件是否正確,返回OK既正確。代碼如下
- /usr/local/nginx/sbin/nginx -t
複製代碼 [root@c7-node1 ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
2.然後啟動Nginx,執行命令
- /usr/local/nginx/sbin/nginx
複製代碼 按Enter鍵即可。查看進程是否已啟動,代碼如下:
[root@c7-node4 ~]# ps -ef | grep nginx
root 6892 1 0 10:40 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
www 6893 6892 0 10:40 ? 00:00:00 nginx: worker process
root 7082 1431 0 11:29 pts/0 00:00:00 grep --color=auto nginx
Centos 7默認防火墻是沒打開80端口,需要以下命令打開80端口:
#查看防火墻運行情況
#打開80端口
- firewall-cmd --zone=public --add-port=80/tcp --permanent
複製代碼 #重啟防火墻
- systemctl restart firewalld.service
複製代碼
通過瀏覽器訪問Nginx默認測試頁面。出現Welcome to nginx!就代表安裝成功
|
|