$ yum -y install make zlib zlib-devel gcc gcc-c++ libtool openssl openssl-devel pcre pcre-devel //PCRE 做用是讓 Nginx 支持 Rewrite 功能
一、下載Nginx至文件夾/usr/local內html
$ cd /usr/local/ //進入目標目錄 $ wget http://nginx.org/download/nginx-1.14.2.tar.gz //下載nginx,選擇穩定版本
二、解壓縮文件包nginx
$ tar zxvf nginx-1.14.2.tar.gz
三、進入安裝目錄,編譯安裝c++
$ cd nginx-1.14.2 $ ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-pcre --with-http_ssl_module $ make $ make install
安裝完成後的摘要信息:tcp
Configuration summary + using system PCRE library + using system OpenSSL 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"
默認安裝到/usr/local/nginx目錄。工具
四、查看Nginx版本網站
$ /usr/local/nginx/sbin/nginx -v
輸出結果以下:
nginx version: nginx/1.14.2
到此,nginx安裝完成。.net
五、啓動、關閉Nginxcode
檢查配置文件是否正確htm
$ /usr/local/nginx/sbin/nginx -t $ /usr/local/nginx/sbin/nginx -V //能夠看到編譯選項
啓動Nginxblog
$ /usr/local/nginx/sbin/nginx // 啓動 $ /usr/local/nginx/conf/nginx.conf //配置文件
從新載入配置文件
$ /usr/local/nginx/sbin/nginx -s reload
重啓Nginx,不會改變啓動時指定的配置文件
$ /usr/local/nginx/sbin/nginx -s reopen
中止Nginx
$ /usr/local/nginx/sbin/nginx -s stop
或
$ pkill nginx
具體配置可搜索,這裏不作介紹
配置文件nginx.conf,位置
/usr/local/nginx/conf/nginx.conf
CentOS7默認的防火牆爲firewall
開啓端口80方法:
$ firewall-cmd --zone=public --add-port=80/tcp --permanent //--permanent永久生效,沒有此參數重啓後失效 $ firewall-cmd --reload //從新載入 $ firewall-cmd --zone=public --query-port=80/tcp //查看 //$ firewall-cmd --permanent --query-port=80/tcp //或者這樣查看 $ firewall-cmd --zone=public --remove-port=80/tcp --permanent //刪除端口
注:參考如下網站
https://blog.csdn.net/wangkai...
https://www.cnblogs.com/moxia...
在騰訊雲安裝參考:
http://www.zhuhongliang.com/a...