前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Mac下安装Nginx与反向代理Tomcat

Mac下安装Nginx与反向代理Tomcat

作者头像
热心的程序员
发布2018-08-30 10:30:00
1.6K0
发布2018-08-30 10:30:00
举报
文章被收录于专栏:编程之路编程之路
1、 安装PCRE
代码语言:javascript
复制
  (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
代码语言:javascript
复制
   (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)若出现错误:

代码语言:javascript
复制
./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)出现错误:

代码语言:javascript
复制
mkdir: /usr/local/nginx: Permission denied

只需要加上在命令前驾驶sudo即可:sudo make install

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

(7)建立软连接:

代码语言:javascript
复制
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

出现下面信息则表示配置成功

代码语言:javascript
复制
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)启动 nginx :sudo nginx

(10)浏览器输入:http://127.0.0.1/

代码语言:javascript
复制
出现如下信息,表示ngix启动成功

Welcome to nginx!

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

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

添加如下配置:

代码语言:javascript
复制
server {
    listen 80 default_server;
    server_name _;
    return 444; # 过滤其他域名的请求,返回444状态码
}

server {
    listen 80;
    server_name 192.168.1.115; # www.aaa.com域名 或 ip 192.168.1.115(本机ip)
    location / {
        proxy_pass http://localhost:8080; # 对应端口号8080
    }
}

重启 nginx ,直接访问 192.168.1.115即可访问到tomcat,原始访问为:192.168.1.115:8080.

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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017.05.16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1、 安装PCRE
  • 2、 安装ngix
  • 3、反向代理本地tomcat ,将本地80端口映射为8080端口,修改nginx配置 /usr/local/nginx/conf/nginx.conf
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档