码迷,mamicode.com
首页 > 其他好文 > 详细

nginx rewrite

时间:2017-04-07 11:18:30      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:nginx rewrite

apache和nginx区别主要在pathinfo的处理, 直接拿去用:

location / { 

    if (!-e $request_filename) { 

       rewrite ^(.*)$ /index.php?$1 last;  break; 

     } 

}

附上本人的配置文件:

server {

listen 80;

server_name redis.yanjiadong.net;

index index.php index.html;

root /alidata/www/redis;

location / {

if (!-e $request_filename) {

rewrite ^(.*)$ /index.php?s=$1 last; break;

}

}

location ~ .*\.(php|php5)?$

{

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi.conf;

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

{
expires 30d;

}

location ~ .*\.(js|css)?$

{
expires 1h;

}
access_log /data/log/access/redis.log;
}

点法的nginx.conf:

server{

        listen 80;

        server_name  wiki.idianfa.com ;

        root /alidata/app/project/application/;

        index index.html index.htm index.shtml index.php;


#       error_page  404               /404.html;

    #Custom rules Start

    if (-f $request_filename/index.html){

rewrite (.*) $1/index.html break;

}

if (-f $request_filename/index.php){

rewrite (.*) $1/index.php;

}

if (!-f $request_filename){

rewrite (.*) /index.php;

}    #Custom rules End

    location = /500.html {

        root   /usr/share/nginx/html;

    }


    location ~ \.php$ {

        fastcgi_pass   unix:/dev/shm/php.sock;

        include        fastcgi_params;

        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

       # access_log     /a/apps/nginx/logs/idianfa.com.access.log main;

    }

        location ~ .*\.(js|css)?$

        {

                expires 1d;

        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)?$

        {

                expires 15d;

        }

    location ~ /\.ht {

        deny  all;

    }

}




再来一发:

user  nginx;

worker_processes  1;

worker_rlimit_nofile 65535;

events {

        use epoll;

        worker_connections 65535;

}


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 /a/apps/nginx/logs/access.log  main;

        error_log  /a/apps/nginx/logs/error.log warn;


    sendfile            on;

        send_timeout        120s;

    tcp_nopush          on;

    tcp_nodelay         on;

    server_tokens       off;

    keepalive_timeout   360s;

    keepalive_requests  1000;


    gzip                on;

    gzip_min_length     1k;

    gzip_buffers        4 16k;

    output_buffers      1 512k;

    postpone_output     1460;

    gzip_comp_level     4;

    gzip_vary           on;


        fastcgi_connect_timeout      300;

        fastcgi_send_timeout         300;

        fastcgi_read_timeout         300;

        fastcgi_buffer_size          512k;

        fastcgi_buffers              8 512k;

        fastcgi_busy_buffers_size    512k;

        fastcgi_temp_file_write_size 512k;

    fastcgi_intercept_errors     on;


        server_names_hash_bucket_size 128;

        client_header_buffer_size     32k;

        large_client_header_buffers   4 32k;

        client_max_body_size          100m;

        client_header_timeout         120s;

    client_body_timeout           120s;


        proxy_connect_timeout      60;

        proxy_read_timeout         60;

        proxy_send_timeout         60;

 proxy_buffer_size          64k;

        proxy_buffers              64 64k;

        proxy_busy_buffers_size    128k;

        proxy_temp_file_write_size 128k;


    ssi on;

        ssi_silent_errors on;

        ssi_types text/shtml;


    server {

            listen       80 default;

            server_name  "";


            root /a/apps/zhujibao/manager/linuxdef;

                index index.html index.htm index.shtml index.php;


                location ~ \.php$ {

                        fastcgi_pass   unix:/dev/shm/php.sock;

                        include        fastcgi_params;

                        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

                }

        }


    server{

                listen  9999;

                server_name x.admin5.com;

                root /a/apps/zhujibao/manager/public;

                index index.html index.htm index.shtml index.php;


                if (!-e $request_filename) {

                        rewrite ^.*$ /index.php last;

                }


                location ~ \.php$ {

                        fastcgi_pass   127.0.0.1:9001;

                        include        fastcgi_params;

                        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

                        access_log     /a/apps/nginx/logs/zhujibao.access.log main;

                }


                location ~ /\.ht {

                        deny  all;

                }

        }


        include vhosts/*.conf;

}




nginx rewrite

标签:nginx rewrite

原文地址:http://jinjiang2009.blog.51cto.com/6625258/1913698

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!