您的位置:首页 > 运维架构 > Nginx

Nginx一些知识整理

2015-05-13 11:37 246 查看
1、Nginx支持PHP,启用以行就可以
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
2、Nginx登录认证及访问控制
location /soft/ {
root /home;
index index.php index.html index.htm;
auth_basic "访问需要权限,请输入帐号密码";
auth_basic_user_file /home/soft/.htpasswd;
deny 10.10.0.10; #访问控制
}
设置密码:htpasswd -cbm /home/soft/conf/htpasswd user01 123456

3、Nginx反向代理
location ~\.php$ {
root html;
index index.php index.html index.htm;
proxy_pass http://10.10.0.226; proxy_set_header X-Real-IP $remote_addr;
}
proxy_set_header X-Real-IP $remote_addr;可以访问的时候记录真实的IP地址,需要在后端web配置文件中修改日志LogFormat "%{X-Real-IP}i

4、负载均衡
upstream webs {
server 10.10.0.226 weight=1;
server 10.10.0.225 weight=1 max_fails=2 fail_timeout=2;
server 127.0.0.1:8080 backup;
}

server {
listen 8080;
server_name localhost;
root /home/xx;
index index.html;
}

5、缓存功能
在server之外定义:
proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=one:20m max_size=1g;
# 验证是否使用缓存成功
add_header X-Via-IP $server_addr;
add_header X-Cache-Status $upstream_cache_status;

proxy_cache one;
proxy_cache_valid 200 302 301 10m;

6、重写功能
rewrite ^/home/(.*)$ http://10.10.0.226/soft/; 本文出自 “ngames” 博客,请务必保留此出处http://ngames.blog.51cto.com/3187187/1650910
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: