nginx的配置

1、配置

#一个server就是一个虚拟主机 
server {
        listen       80;//默认端口
        server_name  222.143.39.129;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;//安装目录下面的相对目录,绝对路径也可以
            index  index.html index.htm;//欢迎页
        }
#配置的错误界面,也可以不配置
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

静态资源文件(例如图片服务器)

通过端口区分不同的虚拟主机

server {
        listen       80;//默认端口
        server_name  222.143.39.129;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;//安装目录下面的相对目录,绝对路径也可以
            index  index.html index.htm;//欢迎页
        }
server {
        listen       81;//默认端口
        server_name  222.143.39.129;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;//安装目录下面的相对目录,绝对路径也可以
            index  index81.html index.htm;//欢迎页
        }

通过域名区分(一个ip挂多个域名,但是一个域名只能对应一个IP):

server {
        listen       80;//默认端口
        server_name  www.baidu.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;//安装目录下面的相对目录,绝对路径也可以
            index  index.html index.htm;//欢迎页
        }
server {
        listen       80;//默认端口
        server_name www.163.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;//安装目录下面的相对目录,绝对路径也可以
            index  index.html index.htm;//欢迎页
        }

反向代理:nginx请求的转发,转发至应用服务器。

配置

upstream sina{
    server 192.168.25.148:8080
}
server {
        listen       80;//默认端口
        server_name  www.sina.com;
        location / {
            #root   html;#root代表直接访问的根路径
            proxy_pass  http://sina;#proxy_pass映射到其他的应用服务器,前面应声明应用服务器地址
            index  index.html index.htm;//欢迎页
        }


upstream baidu{
    server 192.168.25.148:8080
}
server {
        listen       80;//默认端口
        server_name  www.baidu.com;
        location / {
            #root   html;#root代表直接访问的根路径
            proxy_pass  http://baidu;#proxy_pass映射到其他的应用服务器,前面应声明应用服务器地址
            index  index.html index.htm;//欢迎页
        }

负载均衡:

upstream baidu{
    server 192.168.25.148:8080;
    server 192.168.25.148:8081 weight=2;//默认是1,整数
}
server {
        listen       80;//默认端口
        server_name  www.baidu.com;
        location / {
            #root   html;#root代表直接访问的根路径
            proxy_pass  http://baidu;#proxy_pass映射到其他的应用服务器,前面应声明应用服务器地址
            index  index.html index.htm;//欢迎页
        }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值