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/;