CentOS 7伺服器下Nginx安裝配置

weixin_33766168發表於2018-06-07

一、安裝編譯工具及庫檔案

$ yum -y install make zlib zlib-devel gcc gcc-c++ libtool  openssl openssl-devel pcre pcre-devel  //PCRE 作用是讓 Nginx 支援 Rewrite 功能

二、安裝Nginx

1、下載Nginx至資料夾/usr/local內

$ cd /usr/local/     //進入目標目錄
$ wget http://nginx.org/download/nginx-1.14.2.tar.gz  //下載nginx,選擇穩定版本

2、解壓縮檔案包

$ tar zxvf nginx-1.14.2.tar.gz

3、進入安裝目錄,編譯安裝

$ cd nginx-1.14.2
$ ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-pcre  --with-http_ssl_module
$ make
$ make install

安裝完成後的摘要資訊:

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目錄。

4、檢視Nginx版本

$ /usr/local/nginx/sbin/nginx -v

輸出結果如下:
nginx version: nginx/1.14.2
到此,nginx安裝完成。

5、啟動、關閉Nginx

檢查配置檔案是否正確

$ /usr/local/nginx/sbin/nginx -t
$ /usr/local/nginx/sbin/nginx -V     //可以看到編譯選項

啟動Nginx

$ /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配置

具體配置可搜尋,這裡不做介紹
配置檔案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...

相關文章