静态文件服务器
修改nginx.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
#配置静态文件目录
root /root/app/;
#配置首页
index index.html index.htm;
#autoindex在浏览器显示文件目录
autoindex off;
#限制访问速度
set $limit_rate 100k;
}
}
如果访问出现Nginx 403 Forbidden
,在nginx.conf头部添加:
user root;
开启gzip
在http指令块下添加:
gzip on;
gzip_min_length 100;
gzip_comp_level 1;
gzip_buffers 4 8k;
gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg img/gif image/pn
g;
反向代理
根据路径后缀配置反向代理到tomcat,启动一台tomcat,请求地址 http://localhost/test1
。
修改nginx.conf,在serer指令块下添加:
location /test1 {
proxy_pass http://localhost:8081/;
}
配置成功后,test1
后缀的链接都会被代理到Nginx服务器的8081端口上。
负载均衡
修改nginx.conf,在http指令块下添加:
upstream cat {
server localhost:8081;
server localhost:8082;
}
server指令块下添加:
location /test {
proxy_pass http://test/;
}