Mac下安裝Nginx與反向代理Tomcat

1、 安裝PCRE
  (1)下載PCRE安裝包:http://www.pcre.org/
  
  (2)解壓后,cd pcre-8.35。
  
  (3)編譯安裝:
  
  ./configure --prefix=/usr/local
  
  make && make install
  
  (4)查看版本:pcre-config --version
2、 安裝ngix
   (1)下載 Nginx,下載地址:http://nginx.org/download

   (2)解壓后,cd nginx-1.13.0。

   (3)編譯安裝

   ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-cc-opt="-Wno-deprecated-declarations"

   make

   make install

(4)若出現(xiàn)錯(cuò)誤:

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.

安裝新版本:brew upgrade openssl

鏈接最新的openssl版本:brew link openssl --force

(5)出現(xiàn)錯(cuò)誤:

mkdir: /usr/local/nginx: Permission denied

只需要加上在命令前駕駛sudo即可:sudo make install

(6)查看nginx版本:/usr/local/nginx/sbin/nginx -v

(7)建立軟連接:

sudo ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx

sudo ln -s /usr/local/nginx/conf /etc/nginx

sudo ln -s /usr/local/nginx/logs/nginx.pid /var/run/nginx.pid

sudo ln -s /usr/local/nginx/logs /var/log/nginx

(8)檢查配置:sudo nginx -t

出現(xiàn)下面信息則表示配置成功

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

(9)啟動(dòng) nginx :sudo nginx

(10)瀏覽器輸入:http://127.0.0.1/


出現(xiàn)如下信息,表示ngix啟動(dòng)成功

Welcome to nginx!

(11)停止nginx :sudo nginx -s stop

3、反向代理本地tomcat ,將本地80端口映射為8080端口,修改nginx配置 /usr/local/nginx/conf/nginx.conf

添加如下配置:

server {
    listen 80 default_server;
    server_name _;
    return 444; # 過(guò)濾其他域名的請(qǐng)求,返回444狀態(tài)碼
}

server {
    listen 80;
    server_name 192.168.1.115; # www.aaa.com域名 或 ip 192.168.1.115(本機(jī)ip)
    location / {
        proxy_pass http://localhost:8080; # 對(duì)應(yīng)端口號(hào)8080
    }
}

重啟 nginx ,直接訪(fǎng)問(wèn) 192.168.1.115即可訪(fǎng)問(wèn)到tomcat,原始訪(fǎng)問(wèn)為:192.168.1.115:8080.

到此Nginx安裝完畢,并且可以代理本地tomcat。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容