`
haoningabc
  • 浏览: 1465640 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

nginx rewrite替代apache rewrite

阅读更多
清理chrome的缓存
chrome://appcache-internals/

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

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的
一定要设置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相同。

分享到:
评论

相关推荐

    nginx替代方案,nginx代替apache与jboss

    ### Nginx 作为 Apache 和 JBoss 的替代方案 #### 背景介绍 随着互联网技术的不断发展,网站流量的增长对服务器性能提出了更高要求。Apache 和 JBoss 是两种广泛使用的 Web 服务器和应用服务器,但在高并发场景下,...

    实战Nginx取代Apache的高性能Web服务器_文字版

    在很多场景下,Nginx被用作替代Apache服务器的选择,尤其是在高流量网站和需要负载均衡的环境中。本实战指南旨在探讨如何通过Nginx实现高性能的Web服务,以提升网站的响应速度和稳定性。 一、Nginx与Apache的性能...

    实战Nginx:取代Apache的高性能Web服务器.

    在互联网行业中,Nginx经常被用来替代传统的Apache服务器,以应对高并发访问和大型网站的需求。本教程将深入探讨Nginx如何实现这一转变,并介绍其核心特性。 一、Nginx的优势 1. 非阻塞I/O模型:与Apache的多进程...

    nginx rewrite规则

    与Apache的`mod_rewrite`模块相比,Nginx的`rewrite`规则在语法和工作方式上有所不同,这使得理解并熟练掌握Nginx的`rewrite`规则成为提升服务器配置能力的关键。 **1. Nginx与Apache的Rewrite规则对比** Apache的...

    实例讲解nginx的rewrite规则

    ### 实例讲解Nginx的rewrite规则 #### 正则表达式匹配 在Nginx中,使用`rewrite`指令可以实现对URL的重写,其中涉及到正则表达式的匹配方式有以下几种: 1. **区分大小写的匹配**:使用`~`符号,例如:`rewrite ^/...

    实战Nginx.取代Apache的高性能Web服务器

    7.5 Nginx与Apache的Rewrite规则实例对比 第8章 Nginx模块开发 8.1 Nginx模块概述 8.2 Nginx模块编写实践 第9章 Nginx的Web缓存服务与新浪网的开源NCACHE模块 9.1 什么是Web缓存? 9.2 Nginx的Web缓存服务 ...

    浅谈apache和nginx的rewrite的区别

    1. Nginx Rewrite规则相关指令 Nginx Rewrite规则相关指令有if、rewrite、set、return、break等,其中rewrite是最关键的指令。一个简单的Nginx Rewrite规则语法如下: ...2. Nginx与Apache的Rewrite规则实例对比  简单

    nginx设置rewrite规则

    你可以在这个文件中按照Nginx的语法编写规则,它与Apache的`.htaccess`文件类似,但格式和处理方式略有不同。 例如,如果你希望把`http://lin_cli.its.cn/Product/index/pid/35`这样的URL重写为`/index.php/$1`,你...

    实战Nginx_取代Apache的高性能Web服务器_代码

    本实战教程将深入探讨如何使用Nginx取代Apache,以提升Web服务的性能。 1. **Nginx与Apache的区别** Nginx采用异步非阻塞的事件驱动模型,每个工作进程可以同时处理大量的连接,而Apache则主要采用多进程或线程...

    实战Nginx:取代Apache的高性能Web服务器

    实战Nginx:取代Apache的高性能Web服务器,这是一本很不错的书。能够帮助大家搭建一个高性能的web服务器 第1章 Nginx简介.pdf 第2章 Nginx服务器的安装与配置.pdf 第3章 Nginx的基本配置与优化.pdf 第4章 Nginx与PHP...

    实战Nginx.取代Apache的高性能Web服务器.2010

    ### 实战Nginx:取代Apache的高性能Web服务器 #### Nginx简介及选择理由 ...- **Nginx与Apache的Rewrite规则实例对比**:对比Nginx和Apache在处理相同需求时的rewrite规则差异,帮助理解两者之间的异同。

    nginx rewrite重写规则与防盗链配置方法教程详解

    导读:nginx rewrite重写规则与防盗链配置方法,rewrite规则格式中flag标记的几种形式,盗链时返回403错误,允许的域名直接跟在第二行的域名后面。 nginx rewrite重写规则与防盗链配置方法如下所示: nginx rewite...

    Nginx实战:取代Apache的高性能Web服务器

    第7章 Nginx的Rewrite规则与实例 第8章 Nginx模块开发 第9章 Nginx的Web缓存服务与新浪网的开源NCACHE模块 第10章 Nginx在国内知名网站中的应用案例 第11章 Nginx的非典型应用实例 第12章 Nginx的核心模块 第13章 ...

    实战Nginx:取代Apache的高性能Web服务器 张宴.扫描版

    《实战Nginx:取代Apache的高性能Web服务器》是一本由张宴编著的专业书籍,主要探讨了如何利用Nginx作为Web服务器来替代传统的Apache,以实现更高效的网络服务。Nginx以其异步非阻塞I/O模型、模块化设计以及出色的...

Global site tag (gtag.js) - Google Analytics