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: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)
可以直接启动nginx,重新生成nginx.pid就可以了:
1
$ nginx
如果直接启动还是不可行,执行nginx -t查看nginx配置文件路径:
1 2 3
$ 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文件:
1
$ nginx -c /usr/local/etc/nginx/nginx.conf
再次重启nginx -s reload,就不会报错了
3.3. nginx实现反向代理
实现分布式下负载均衡
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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{ listen 9000; server_name localhost; location /{ proxy_pass http://tomcat; } } }