nginx rewrite替代apache rewrite
清理chrome的缓存
chrome://appcache-internals/
nginxrewrite
参考
http://seanlook.com/2015/05/17/nginx-location-rewrite/
wgethttp://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的
一定要设置PHP_FCGI_MAX_REQUESTS=0
否则最大连接数是500
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就可以退休了
https://github.com/killinux/jslinux-network
注意一些全局变量,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相同。