zoukankan      html  css  js  c++  java
  • Linux--nginx域名绑定-url rewrite

    进入/usr/local/nginx/conf

    编辑 nginx.conf
    绑定域名:
    添加一个 server元素,更改后的配置内容可能如下:
    server
    {
    listen       80;
    server_name xmdm.easymobi.cn;
    index index.html index.htm index.php;
    root  /home/wwwroot;
    location ~ .*.(php|php5)?$
    {
    fastcgi_pass  unix:/tmp/php-cgi.sock;
    fastcgi_index index.php;
    include fcgi.conf;
    }
    location /status {
    stub_status on;
    access_log   off;
    }
    location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
    {
    expires      30d;
    }
    location ~ .*.(js|css)?$
    {
    expires      12h;
    }
    log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
                 '$status $body_bytes_sent "$http_referer" '
                 '"$http_user_agent" $http_x_forwarded_for';
    access_log  /home/wwwlogs/xmdm.log  access;
    }
    这里,就将域名:xmdm.easymobi.cn 绑定到该机器上.如果要绑定另外一个,则再添加一个server.
    添加自己的 server 时要注意的是:log_format access 后的格式不能是一样。不然会报错。
     
    url - rewrite:
    经常看到如下链接:
    http://www.ssss.com/3/4/cmd
    这个 http 请求经过 web 服务器时,会被rewrite 规则解析成另一个地址,如:http://www.ssss.com/index.php?a=3&b=4&c=cmd
    如果没有定义rewrite规则,上面的地址肯定就无法找到了。
    nginx的定义方法和apache的非常相似,如下:
    location / {
    rewrite ^/category/(d+)/(.+)/(d+)$ /category.php?cateId=$1&nowPage=$3 last;
    rewrite ^/detail/(d+)/(.+)$ /detail.php?id=$1 last;
    rewrite ^/result/(.+)/(d+)/(d+)$ /result.php?keyword=$1&id=$2&nowPage=$3 last;
    rewrite ^/result/(d+)/(d+)$ /result.php?id=$1&nowPage=$2 last;
    }
    location / 表示访问域名根目录下的地址
    下面rewrite 后有两个正则表达式,前面一个是用户输入的地址;后面是要转义成的。
    编辑完成后,需要重新加载 nginx:
    进入usr/local/nginx/sbin
    执行: ./nginx -s reload
     
    下面贴一个 apache 下的设置方式:
    <IfModule mod_rewrite.c>
    RewriteEngine on 
    RewriteRule ^/?category/(d+)/(.+)/(d+)$ category.php?cateId=$1&nowPage=$3 [L]
    RewriteRule ^/?detail/(d+)/(.+)$ detail.php?id=$1 [L]
    RewriteRule ^/?result/(.+)/(d+)/(d+)$ result.php?keyword=$1&id=$2&nowPage=$3 [L]
    RewriteRule ^/?result/(d+)/(d+)$ result.php?id=$1&nowPage=$2 [L]
    </IfModule>
    这一段我是放在 .htaccess 中的。
  • 相关阅读:
    themes、skins
    使用GreyBox实现Ajax模式窗口
    .net最小化到系统托盘
    asp.net自定义控件
    [转]SQL函数的简短说明
    prototype1.4 和1.5
    [转]Oracle PL/SQL 编程手册(SQL大全)
    更新同一张表中的数据的方法
    js中eval()的作用
    asp.net中的中文和特殊字符的处理方式!
  • 原文地址:https://www.cnblogs.com/webnote/p/5863651.html
Copyright © 2011-2022 走看看