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)若出现错误:
./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)出现错误:
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
出现下面信息则表示配置成功
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/
出现如下信息,表示ngix启动成功
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; # 过滤其他域名的请求,返回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。