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;
}
1126

被折叠的 条评论
为什么被折叠?



