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
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
相关文章推荐
- 一些以前学习的Android知识的整理(1)。
- 2012.12.10整理一些编码的知识
- 关于特征工程入门中的一些基本知识(整理)
- 一些简单知识的整理—C语言(一)
- DIVCSS网页布局常用的一些基础知识整理
- 接口自动化测试项目的一些知识整理
- JS事件知识的一些小整理
- 一些iphone基础知识的整理
- [知识整理]Linux系统WIFI知识的一些整理
- 一些以前学习Android的知识整理(2)
- 整理的一些面试常问语言知识
- [知识整理]Linux系统WIFI知识的一些整理
- Linux入门的一些基本知识整理
- 在react native用到的javascript 的一些关键知识(整理中)
- 一些C#相关知识整理
- 参考别人的代码整理的一些 javascript 有关日期时间的一些知识
- IOS开发中,一些涉及到的基础知识整理
- nginx一些基础知识、搭建和mysql主从复制搭建
- 搜集的一些不错的技术分享和知识整理的网站
- 关于特征工程入门中的一些基本知识(整理)