Nginx学习(一)

Nginx

1、install

Mac

brew install nginx

2、启动

指定配置文件启动
nginx -c ~/develop/install/nginx/nginx.conf

检查配置文件是否有错
nginx -t 

重启
nginx -s reload

停止
nginx -s stop

3、server 虚拟主机

http节点下可以配置多个server,配置如下:

server {
    listen       80;
    server_name  localhost;

    location / {
        root html;
    }
}
  • 通过端口区分

    server_name一致时,通过监听不同的端口区分虚拟主机

  • 通过域名访问

    监听相同端口时,通过http header中的Host,查找匹配server_name的虚拟主机

4、反向代理

启动两个tomcat,端口号分别为8888、9999。

增加如下配置:

upstream nginx {
    server localhost:8888;
    server localhost:9999;
}

修改如下配置

location / {
    # root /Users/zhang/develop/install/nginx/html1;
    proxy http://nginx
}

你可能感兴趣的:(Nginx学习(一))