linux安裝和使用nginx__linux

來源:互聯網
上載者:User

Nginx 是一個高效能的 HTTP 和 反向 Proxy 伺服器,也是一個 IMAP/POP3/SMTP Proxy 伺服器。

想要Linux下安裝Nginx作為WEB伺服器,要先準備些必要的庫和工具,通常必須安裝的是:PERC庫和Openssl。

1. 安裝PCRE庫(Nginx的rewrite模組和HTTP核心模組會用到PCRERegex文法)

使用yum來安裝:

 yum install pcre pcre-devel

2.安裝OpenSSL(若伺服器提供安全網頁(https://)時,會用到OpenSSL庫)

# yum install openssl openssl-devel

3.下載、解壓Nginx

去http://nginx.org/下載你要使用的版本,放到home目錄,然後解壓

# tar zxf nginx-1.12.2.tar.gz

4.安裝Nginx

建立一個應用程式通常分為三步:從原始碼到配置、編譯和安裝編譯

需要使用root使用者安裝

1) 進入解壓完的nginx目錄,執行下面命令 

 ./configure  --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module 2)root# make

3)root# make install

預設安裝位置在 /usr/local/nginx

5.啟動和停止Nginx

 進入/usr/local/nginx/sbin/ ,執行  nginx  即可啟動

以非root許可權啟動時,會出現 nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied) 錯誤 原因:Linux只有root使用者可以使用1024一下的連接埠

停止時 使用    nginx -s stop命令

6.配置Nginx.conf

 如果要使用nginx做負載平衡,一般要單獨配置conf檔案。

1)建立一個 name為 webapp.conf 的設定檔,內容如下:

      upstream  backend {
      server ip1:8000;
      server ip2:8000;
    }
   server {
        listen       80;
        location /web {
        proxy_pass http://backend;
      }

    }

2) 修改conf目錄下的nginx.conf檔案

    在 include   mime.types; 

    之後增加      include    webapp.conf;

    將 包含80連接埠的 server {

        xxxxxxxxx

        }

       給注釋掉。

3) 先 執行 nginx -s stop 停止,再執行  nginx 啟動。

4)    在瀏覽器中 執行  localhost/web  ,即可 將請求轉寄至配置好的2台app伺服器上。

具體的配置資訊可以參考一下的部落格

https://www.cnblogs.com/Steward-Xu/p/6703295.html

https://blog.csdn.net/daybreak1209/article/details/51554045


      

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.