使用场景:
    两个不同端口的微服务,当我们测试的时候,需要放到同一台服务器上,共享80端口访问。
    可以在nginx.conf中做如下配置:

    1. server {
    2. listen 80;
    3. server_name apitest.aa.com;
    4. location / {
    5. proxy_pass http://10.26.31.176:8081; #微服务地址测试环境
    6. root html;
    7. index index.html index.htm;
    8. }
    9. }
    10. server {
    11. listen 80;
    12. server_name api.aa.com;
    13. location / {
    14. proxy_pass http://10.26.31.176:8080; #微服务地址线上环境
    15. root html;
    16. index index.html index.htm;
    17. }
    18. }

    做好上述配置,我们就可以愉快的进行测试了。
    注意:修改完成之后,要重载下配置才能生效。

    1. #重载配置文件 需要进入nginx安装目录 执行如下命令
    2. sbin/nginx -s reload