Nginx的安裝和部署

  • 在作項目的時候,咱們須要一個專門的服務器來接收並保存圖片,這樣就須要在圖片服務器上安裝一個http服務器, 可使用: Tomcat, Apache, Nginx, 這裏咱們介紹一下Nginx在Linux上的安裝和部署.
  • Nginx通常推薦安裝到Linux系統, 由於Nginx是用C語言開發的,因此須要安裝c語言的編譯環境gcc.
  • 1,進入 http://nginx.org/en/download.html 下載 nginx 版本:
  • nginx-1.8.0.tar.gz
  • 2,安裝gcc環境:
  • yum install gcc-c++
  • 3,安裝pcre庫:
  • PCRE(Perl Compatible Regular Expressions)是一個 Perl 庫,包括 perl 兼容的正則表達式庫。 nginx 的 http 模塊使用 pcre 來解析正則表達式,因此須要在Linux上安裝pcre庫.
  • yum install -y pcre pcre-devel
  • 注: pcre-devel 是使用 pcre 開發的一個二次開發庫。 nginx 也須要此庫
  • 安裝zlib
  • zlib 庫提供了不少種壓縮和解壓縮的方式, nginx 使用 zlib 對 http 包的內容進行 gzip,因此須要在 linux 上安裝 zlib 庫。
    yum install -y zlib zlib-devel
  • 安裝openssl
  • OpenSSL 是一個強大的安全套接字層密碼庫,囊括主要的密碼算法、經常使用的密鑰和證書封裝管理功能及 SSL 協議,並提供豐富的應用程序供測試或其它目的使用.html

  • nginx 不只支持 http 協議,還支持 https(即在 ssl 協議上傳輸 http),因此須要在 linux安裝 openssl 庫。
    yum install -y openssl openssl-devellinux

  • 如今開始正式安裝:
  • 1.把Nginx的源碼壓縮包上傳到Linux系統.上傳的時候,在CRT中,右鍵選項卡,選擇"鏈接到SETP會話", 將文件直接拖到窗口便可,
  • 2, 解壓縮文件:
  • tar -zxvf nginx-1.8.0.tar.gz
  • 3, 進行configure .執行configure進行編譯源碼
  • 直接在[root@localhost nginx-1.8.0] 編譯這段代碼:nginx

    ./configure --prefix=/usr/local/nginx --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --http-scgi-temp-path=/var/temp/nginx/scgic++

  • 4,而後執行make
  • 5,執行,make install
  • 6,這時會發現/usr/local 目錄下會多一個nginx
  • 7,nginx的啓動:
  • 啓動:進入/user/local/nginx 的 sbin 目錄, ./nginx 就能夠啓動。
  • 8,查看進程:
  • [root@localhost sbin]# ps aux|grep nginx
  • 9.而後經過IP訪問.
  • 10,若是訪問不到,要查看防火牆是否關閉:
  • service iptables restart
  • 11.關閉nginx:
  • 可使用 kill 命令,可是不推薦使用:kill 4746(這個是root後邊的值)
  • 快速中止: ./nginx -s stop
    cd /usr/local/nginx/sbin
    ./nginx -s stop
    此方式至關於先查出 nginx 進程 id 再使用 kill 命令強制殺掉進程
  • 完整中止:
  • 完整中止(建議使用): ./nginx -s quit
    cd /usr/local/nginx/sbin
    ./nginx -s quit
    此方式中止步驟是待 nginx 進程處理任務完畢進行中止
  • 12.刷新配置:
  • a. 從新加載配置文件
    當 nginx 的配置文件 nginx.conf 修改後,要想讓配置生效須要重啓 nginx,使用-s reload
    不用先中止 nginx 再啓動 nginx 便可將配置信息在 nginx 中生效,以下:
    ./nginx -s reload
  • 13, 先中止再啓動(建議使用):
    對 nginx 進行重啓至關於先中止 nginx 再啓動 nginx, 即先執行中止命令再執行啓動命
    令。以下:
    ./nginx -s quit
    ./nginx正則表達式

  • 14 .nginx的配置:
  • 在/usr/local/nginx/conf 目錄下 nginx.conf 文件是 nginx 的配置文件。
  • server是一個虛擬機,80 是端口,算法

安裝完畢!

相關文章
相關標籤/搜索