nginx安装及使用-MacOS

1 篇文章 0 订阅

brew install nginx

$ brew install nginx 

==> nginx
Docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

nginx will load all files in /usr/local/etc/nginx/servers/.

To have launchd start nginx now and restart at login:
  brew services start nginx
Or, if you don't want/need a background service you can just run:
  nginx

运行nginx

$ brew services start nginx
$ 
$
$ nginx -s stop
$ nginx -s reload

访问 http://localhost:8080

配置nginx

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-s17FiXpb-1587286731721)(/nginx.png)]

$ cd /usr/local/Cellar/nginx/1.17.8/

/usr/local/etc/nginx/nginx.conf

代理配置

路径中存在eduservice 转至 http://localhost:8001 tomcat运行路由

server {
        listen       9500;
        server_name  localhost;   
        
        location / {
            root   html;
           index  index.html index.htm;
        }

        location ~ /eduservice/ {
            proxy_pass http://localhost:8001;
        }
 }

启动异常

nginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)

可以直接启动nginx,重新生成nginx.pid就可以了:

$ nginx

如果直接启动还是不可行,执行nginx -t查看nginx配置文件路径:

$ nginx -t
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful

指定一下conf文件:

$ nginx -c /usr/local/etc/nginx/nginx.conf

再次重启nginx -s reload,就不会报错了

nginx实现反向代理

请求都转发到tomcat,实现分布式下负载均衡

http{
	upstream tomcat{
	   server 192.168.0.112:8080 weight=20;
	   server 192.168.0.112:8081 weight=20;
	   server 192.168.0.112:8082 weight=20;
	   server 192.168.0.112:8083 weight=20;
	}
 server{
   listen       9000;
   server_name  localhost;
   location /{
      proxy_pass http://tomcat;
   }
 }
}
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值