linux下安装nginx及配置tomat进行反向代理

nginx高性能的HTTP和反向代理web服务器
使root用户安装
准备安装目录
[root@fangfang ~]# mkdir /usr/local/nginx
[root@fangfang ~]# cd /usr/local/nginx/
解压执
执行:./configure --prefix=/usr/local/nginx
错语信息:
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre= option.
解决办法:
安装pcre-devel与openssl-devel解决问题
yum -y install pcre-devel openssl openssl-devel
./configure --prefix=/usr/local/nginx
make
make install

启动nginx
cd /usr/local/nginx/sbin
命令:./nginx
查看进程号:ps -ef|grep nginx
Master是主进程号
在这里插入图片描述
停止nginx
停止方式
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx -s quit
killall nginx
kill -9 进程号(master)
kill -9 进程号(body)
4.强行停止
Pkill -9 nginx
开始配置工作:
cd /usr/local/nginx/conf
vim nginx.conf
修改端口为:8089
查看修改的文件是否正确:
/usr/local/nginx/sbin/nginx -t
重启nginx
/usr/local/nginx/sbin/nginx -s reload
配置
upstream  tomcat_service {
server 192.168. 126.1:8089;
server 192.168. 126.2:8080;
}
同时我们需要再修改下server,将定向的路径转到自定义服务器集群上。修改location 下的proxy_pass 节点内容。
http:// 后面对应upstream节点中集群的名称,两边一致即可。
server {
listen 8089;
server_name localhost;
charset utf-8;
location / {
proxy_pass http:// tomcat_service;
#root html;
#index index.html index.htm;
}
}

/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
即可在次访问
注意:有时候空格或者分号造成编译不过去 ,会出现编译失败

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值