Nginx配置文件

1、Nginx配置文件

#全局配置,配置影响Nginx整体运行的指定
#处理并发的值,越大越好
worker_processes  1;
# 配置影响Nginx服务器与用户网络的配置
events {
#支持最大连接数
    worker_connections  1024;
}
#http :反向代理。配置最频繁的部分
#http全局:
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;  

#与虚拟主机有密切相关
    server {
监听端口
        listen       80;
虚拟主机的名称或者IP地址
        server_name  localhost;
# 		server_name  192.168.12.23;    Nginx的地址或者名字。
#基于Nginx服务器接收到的请求字符串对虚拟主机名称之外的字符串进行配置,对特定的请求进行处理。地址定向。数据缓存、应答控制等都在这里配置
        location / {
            root   html;
			#反向代理
			proxy_pass	被代理的路径(真实要访问的地址)http:127.0.0.1:8080

            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        
        location ~ \.php$ {~表示使用了正则表达式
            proxy_pass   http://127.0.0.1;  反向代理 
        }
 
    }

2、反向代理

配置反向代理语法: proxy_pass 要代理的服务器

#全局配置,配置影响Nginx整体运行的指定
#处理并发的值,越大越好
worker_processes  1;
# 配置影响Nginx服务器与用户网络的配置
events {
#支持最大连接数
    worker_connections  1024;
}
#http :反向代理。配置最频繁的部分
#http全局:
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;  

#与虚拟主机有密切相关
    server {
监听端口
        listen       80;
虚拟主机的名称或者IP地址      
		server_name  192.168.23.128;    Nginx的地址或者名字。
#基于Nginx服务器接收到的请求字符串对虚拟主机名称之外的字符串进行配置,对特定的请求进行处理。地址定向。数据缓存、应答控制等都在这里配置
        location / {
            root   html;
			#反向代理
			proxy_pass	http:127.0.0.1:8080  # 配置被代理的路径(真实要访问的地址)
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ \.php$ {~表示使用了正则表达式
            proxy_pass   http://127.0.0.1;  反向代理 
        }
    }

3、负载均衡

配置负载均衡语法: upstream name{
server 被代理的服务器
}

3.1 轮询(默认)

#轮询(默认)
upstream fuzaijunhenglist{
   server  192.168.10.2:9001;
   server  192.168.10.2:9002;
}
   location / {
            root   html;
			#反向代理
			proxy_pass	http://fuzaijunhenglist;

            index  index.html index.htm;
			autoindex on;
        }

3.1 加权轮询


#加权轮询
upstream fuzaijunhenglist{
   server  192.168.10.2:9001  weight=10;
   server  192.168.10.2:9002  weight=10;
}
   location / {
            root   html;
			#反向代理
			proxy_pass	http://fuzaijunhenglist;

            index  index.html index.htm;
			autoindex on;
        }

3.1 IpHash

upstream fuzaijunhenglist{
   ip_hash;
   server  192.168.10.2:9001;
   server  192.168.10.2:9002;
}
   location / {     / 后面可以配置其他路径
            root   html;
			#反向代理
			proxy_pass	http://fuzaijunhenglist;

            index  index.html index.htm;
			autoindex on;
        }

3.1 第三方(fair)

upstream fuzaijunhenglist{
    fair;
   server  192.168.10.2:9001;
   server  192.168.10.2:9002;
  
}
  location / {
            root   html;
			#反向代理
			proxy_pass	http://fuzaijunhenglist;

            index  index.html index.htm;
			autoindex on;
        }

4、动静分离

实现动静有两种方法:
1、 把静态资源分离出来做成一个单独的服务器

​ 2、把静态资源和动态资源混合起来,通过Nginx分离

#Nginx动静分离
 location /life/ {
            root   /data/;#静态资源所在的路径
			#反向代理
			proxy_pass	http://fuzaijunhenglist;

            index  index.html index.htm;
           #列出当前文件夹的目录(可以不配置)
			autoindex on;
        }

Nginx简介

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值