linux源碼安裝nginx,並代理後端兩個不同網站(tomcat容器)

來源:互聯網
上載者:User

標籤:alt   2.7   down   版本   地址   檔案   src   bin   cat   

公司的windows伺服器宣布退休,新伺服器我安裝了linux系統。將公司官網從舊伺服器遷出來,兩個官網放在兩個tomcat容器,nginx代理兩個tomcat
以下為具體操作

一、下載相關的依賴庫

pcre http://120.52.73.43/jaist.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.tar.gz

openssl https://www.openssl.org/source/openssl-1.0.2h.tar.gz

zlib http://zlib.net/zlib-1.2.8.tar.gz

nginx http://nginx.org/download/nginx-1.10.0.tar.gz

二、解壓相關依賴庫源碼包

cd /tmptar -zxf nginx-1.10.0.tar.gz tar -zxf pcre-8.38.tar.gztar -zxf zlib-1.2.8.tar.gztar -zxf openssl-1.0.2h.tar.gz

三、建立nginx使用者(這一步很重要,如果使用root啟動nginx會有一些亂七八糟問題。比如:圖片無法載入。踩過的坑後面就別踩了)

groupadd nginxuseradd nginx -g nginx -s /sbin/nologin -M

四、編譯安裝Nginx

cd /tmp/nginx-1.10.0./configure --prefix=/usr/local/nginx --pid-path=/usr/local/nginx/logs/nginx.pid --error-log-path=/usr/local/nginx/logs/error.log --http-log-path=/usr/local/nginx/logs/access.log --with-http_ssl_module --with-pcre=/tmp/pcre-8.38 --with-zlib=/tmp/zlib-1.2.8 --with-openssl=/tmp/openssl-1.0.2h  --user=nginx  --group=nginx

五、編譯安裝

make && make install

六、查看nginx版本

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

七、啟動nginx

/usr/local/nginx/sbin/nginx

八、修改主設定檔

cd /usr/local/nginx/conf/cp nginx.conf  nginx.conf.bakvim nginx.conf  找到http模組並將下面的一行改為include       suray-globl.conf;         #名字可以自訂*.conftouch suray-globl.conf                   #建立suray-globl.conf與設定檔中同名檔案

輸入以下內容

**server {        listen 80;        server_name www.test1.com;        location /{             proxy_pass http://127.0.0.1:8080;    }}server {        listen 80;        server_name www.test2.cn;        location /{             proxy_pass http://127.0.0.1:7070;    }}儲存退出依次建立兩個tomcat容器並將webapps下面的內容清空建立ROOT檔案夾,因為我們公司的網站是靜態網頁我前面location 後面配置為根目錄所以要將網站目錄設定為ROOT這樣輸入欄位名後預設開啟ROOT下面的檔案,如果不設定為ROOT可在location  "/"後面跟上對應的名稱。

linux源碼安裝nginx,並代理後端兩個不同網站(tomcat容器)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.