安装

在 Mac 下可以直接使用 homebrew 安装 nginx

brew search nginx

brew install nginx

启动 nginx: sudo nginx,访问 8080 应能看到欢迎界面

nginx -V 查看 nginx 的启动参数,配置文件的位置默认是 

--conf-path=/usr/local/etc/nginx/nginx.conf 
 

#重新加载配置|重启|停止|退出 nginx
nginx -s reload|reopen|stop|quit 
 

反向代理

 
假设希望别人输入 localhost:8080 时直接跳转到 localhost:2014,那么在 nginx.conf 中配置
 
http {
server {
listen 8080; location / {
proxy_pass http://127.0.0.1:2014;
}
}
}

负载均衡加反向代理

myapp1 是一组网页的集合,这里作为一个变量

http {
upstream myapp1 {
server srv1.example.com;
server srv2.example.com;
server srv3.example.com;
} server {
listen 8080; location / {
proxy_pass http://myapp1;
}
}
}

  

注意:

1. location 后面的东西是一个 uri 地址,/ 的话表示根目录的请求直接跳转到 myapp1 上,当然 uri 还可以更长一些,比如 /name 之类的,具体怎么替换还要结合 proxy_pass 来处理,这里分为两种情况

If the proxy_pass directive is specified with a URI, then when a request is passed to the server, the part of a normalized request URI matching the location is replaced by a URI specified in the directive:

location /name/ {
proxy_pass http://127.0.0.1/remote/;
}

If proxy_pass is specified without a URI, the request URI is passed to the server in the same form as sent by a client when the original request is processed, or the full normalized request URI is passed when processing the changed URI:

location /some/path/ {
proxy_pass http://127.0.0.1;
}

参考

1. http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass

2. https://www.nginx.com/blog/load-balancing-with-nginx-plus-part2/?_ga=1.269115441.1947437472.1438069067

 

nginx 安装与反向代理测试 under MAC的更多相关文章

  1. Nginx 安装以及反向代理配置(windows)

    安装 windows 下 Nginx 安装非常简单,下载地址 http://nginx.org/en/download.html. 选择红框这个,下载下来是个 zip 文件,解压.这时我们双击根目录的 ...

  2. nginx安装,反向代理配置

    1.centos 版本 下载最新稳定版 https://www.nginx.com/resources/wiki/start/topics/tutorials/install/# 2.执行语句: ./ ...

  3. Nginx安装配置&反向代理

    使用Nginx作为前端服务能够更快更及时的响应静态页面.js.图片等,当客户端请求访问动态页面时由Nginx的反向代理给Apache处理,Apache处理完再交予Nginx返回给客户端. Nginx更 ...

  4. Nginx的安装及反向代理设置

    因为项目的缘故,接触到了Nginx的安装和反向代理设置,和大家分享下. 一.Nginx的下载.安装cd /homewget http://nginx.org/download/nginx-1.0.5. ...

  5. Nginx入门教程-简介、安装、反向代理、负载均衡、动静分离使用实例

    场景 Nginx入门简介和反向代理.负载均衡.动静分离理解 https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/102790862 Ub ...

  6. Nginx 部署、反向代理配置、负载均衡

    Nginx 部署.反向代理配置.负载均衡 最近我们的angular项目部署,我们采用的的是Nginx,下面对Nginx做一个简单的介绍. 为什么选择Nginx 轻:相比于Apache,同样的web服务 ...

  7. Nginx介绍与反向代理

    Nginx的产生 没有听过Nginx?那么一定听过它的"同行"Apache吧!Nginx同Apache一样都是一种WEB服务器.基于REST架构风格,以统一资源描述符(Unifor ...

  8. Nginx配置实例-反向代理实例:根据访问的路径跳转到不同端口的服务中

    场景 Ubuntu Server 16.04 LTS上怎样安装下载安装Nginx并启动: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/detai ...

  9. Nginx 七层反向代理

    目录 1.代理 2.正向代理 3.反向代理 4.Nginx 反向代理 5.Nginx 反向代理相关指令介绍 ①.listen ②.server_name ③.location ④.proxy_pass ...

随机推荐

  1. ASP.NET MVC 下拉列表使用小结

    ASP.NET MVC中下拉列表的用法很简单,也很方便,具体来说,主要是页面上支持两种Html帮助类的方法:DropDownList()和DropDownListFor().这篇博文主要作为个人的一个 ...

  2. 改进ConcurrentDictionary并行使用的性能

    上一篇文章“ConcurrentDictionary 对决 Dictionary+Locking”中,我们知道了 .NET 4.0 中提供了线程安全的 ConcurrentDictionary< ...

  3. iOS开发——高级技术&签名机制

    签名机制 最近看了objc.io上第17期中的文章 <Inside Code Signing> 对应的中文翻译版 <代码签名探析> ,受益颇深,对iOS代码签名机制有了进一步的 ...

  4. RTMP协议

    Real Time Messaging Protocol(实时消息传送协议协议)概述   实时消息传送协议是Adobe Systems公司为Flash播放器和服务器之间音频.视频和数据传输开发的私有协 ...

  5. 【VerySky原创】如何查找SNRO编号范围的使用情况;

    SAP所有编号范围的对象都可以在表NRIV中找到:

  6. cmd for 循环拷贝文件

    这几天忙活部署测试环境, 中途需要拷贝 文件, 直接贴code吧: ::/定义原路径 set source=seventrat_test_backend,seventrat_test_frontend ...

  7. Node初学者入门,一本全面的NodeJS教程(转载)

    分类 JS学习   发布 ourjs  2013-12-02 注意 转载须保留原文链接,译文链接,作者译者等信息.     作者: Manuel Kiessling  翻译: goddyzhao &a ...

  8. zz c++ Useful resources

    Useful resources < cpp The Standard C++ Foundation - Non-profit hub for C++ news, articles, and e ...

  9. depth and distance

    1down votefavorite   I'm implementing ominidirectional shadow mapping for point lights. I want to us ...

  10. 10条现代EQ技术基础贴士(转)

    前言: 无论是追求复古的模拟音色还是高精度的透明音质,现代电脑音乐制作中层出不断的新EQ插件以其超强的频率塑形和个性化功能为音色的润色和重塑提供了无限可能. 虽然EQ并不是音频工程工具中最复杂的,但是 ...