nginx rewrite替代apache rewrite

30 篇文章 0 订阅
13 篇文章 0 订阅
清理chrome的缓存
[color=red]chrome://appcache-internals/[/color]

nginx rewrite
参考
[url]http://seanlook.com/2015/05/17/nginx-location-rewrite/[/url]

wget http://www.lighttpd.net/download/spawn-fcgi-1.6.3.tar.bz2

#!/bin/sh
export PHP_FCGI_MAX_REQUESTS=0
/usr/local/spawn/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u haoning -g haoning -f /usr/local/php5/bin/php-cgi -P /var/run/fastcgi-php.pid

这个是跑php的
[color=red]一定要设置PHP_FCGI_MAX_REQUESTS=0
否则最大连接数是500[/color]

nginx装echo模块是为了测试用的
nginx安装

./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=/opt/echo-nginx-module
make
make install

修改nginx配置文件
nginx.conf

#user nobody;
user haoning;
worker_processes 8;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name 192.168.8.61;
#server_name 192.168.0.110;
#charset koi8-r;
charset utf-8;
#access_log logs/host.access.log main;
location / {
root /var/www;
index index.html index.htm;
}
location /jslinux-network/ {
# rewrite hda(.*).bin http://$SERVER_NAME$REQUEST_URI/../disk-expander.php?index=$1;
# rewrite hdb(.*).bin http://$SERVER_NAME$REQUEST_URI/../disk-expander.php?index=$1&hdb=true;
# rewrite ^offlinemanifest.appcache$ http://$SERVER_NAME$REQUEST_URI/../offlinemanifest.php;
# rewrite ^index.html$ http://$SERVER_NAME$REQUEST_URI/../index.php;
# #for rewrite test
#rewrite a.html http://$SERVER_NAME$REQUEST_URI/../b.html last;
rewrite hda(.*).bin /jslinux-network/disk-expander.php?index=$1;
rewrite hdb(.*).bin /jslinux-network/disk-expander.php?index=$1&hdb=true;
rewrite offlinemanifest.appcache$ /jslinux-network/offlinemanifest.php;
rewrite index.html /jslinux-network/index.php last;
rewrite a.html /jslinux-network/b.html last;
root /var/www;
index index.html index.htm;
}
location /hello {
echo -n $document_uri;
}
location ~* \.(gif|jpg|jpeg)$ {
echo -n "haha";
#rewrite \.(gif|jpg)$ /logo.png;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
set $path_info "/";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
#root html;
root /var/www;
}
fastcgi_param SCRIPT_FILENAME /var/www/$real_script_name;
fastcgi_param script_name $real_script_name;
fastcgi_param path_info $path_info;
include /usr/local/nginx/conf/fastcgi_params;
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {
# root html;
# index index.html index.htm;
# }
#}


# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;

# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
# }
#}

}

修改之后
负责 转发的apache就可以退休了
[url]https://github.com/killinux/jslinux-network[/url]

注意一些全局变量,nginx的配置文件中可以直接用的

$args : #这个变量等于请求行中的参数,同$query_string
$content_length : 请求头中的Content-length字段。
$content_type : 请求头中的Content-Type字段。
$document_root : 当前请求在root指令中指定的值。
$host : 请求主机头字段,否则为服务器名称。
$http_user_agent : 客户端agent信息
$http_cookie : 客户端cookie信息
$limit_rate : 这个变量可以限制连接速率。
$request_method : 客户端请求的动作,通常为GET或POST。
$remote_addr : 客户端的IP地址。
$remote_port : 客户端的端口。
$remote_user : 已经经过Auth Basic Module验证的用户名。
$request_filename : 当前请求的文件路径,由root或alias指令与URI请求生成。
$scheme : HTTP方法(如http,https)。
$server_protocol : 请求使用的协议,通常是HTTP/1.0或HTTP/1.1。
$server_addr : 服务器地址,在完成一次系统调用后可以确定这个值。
$server_name : 服务器名称。
$server_port : 请求到达服务器的端口号。
$request_uri : 包含请求参数的原始URI,不包含主机名,如:”/foo/bar.php?arg=baz”。
$uri : 不带请求参数的当前URI,$uri不包含主机名,如”/foo/bar.html”。
$document_uri : 与$uri相同。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值