HTTP rewrite 模块

回复 收藏
本帖最后由 乐橙306 于 2016-3-13 11:17 编辑

参考文档
HTTP   rewrite  模块
http://nginx.org/en/docs/http/converting_rewrite_rules.html

http://nginx.org/en/docs/http/ngx_http_rewrite_module.html

  1. if ($host ~ (www.gc73.com|web.gc73.com|www.gc73.net|www.gc73.cn|web.gc73.cn|gc73.com|wy.pook.com)){
  2. rewrite ^/(.*)$ http://www.pook.com/$1 permanent;
  3. rewrite ^(.*)$ http://www.pook.com$1 permanent;
  4. 1.上面2条rewrite有什么区别?
  5. 2.~ 和 ~*  有什么区别?

2016-03-13 10:48 举报
已邀请:
0

乐橙306

赞同来自:

本帖最后由 乐橙306 于 2016-3-31 14:37 编辑

建议学  nginx  rewrite  模块之前   先把它看懂  

正则表达式
http://www.apelearn.com/bbs/thread-11418-1-1.html

0

乐橙306

赞同来自:

  1. if ($http_user_agent ~ MSIE) {
  2. : rewrite  ^(.*)$  /msie/$1  break;
  3. }
  4. if ($http_cookie ~* "id=([^;] +)(?:;|$)" ) {
  5. : set  $id  $1;
  6. }
  7. if ($request_method = POST ) {
  8. : return 405;
  9. }
  10. if (!-f $request_filename) {
  11. : break;
  12. : proxy_pass  http://127.0.0.1;
  13. }
  14. if ($slow) {
  15. : limit_rate  10k;
  16. }
  17. if ($invalid_referer) {
  18. : return   403;
  19. }
0

乐橙306

赞同来自:

  1. rewrite  ^/users/(.*)$  /show?user=$1?  last;


0

chao901103

赞同来自:

一个 虚拟主机 配置文件中可以写多个if rewrite 吗?
为什么我写完 访问网站 会出现提示 你多次重定向 打不开网站 ??
0

乐橙306

赞同来自:

本帖最后由 乐橙306 于 2016-5-10 09:52 编辑
chao901103 发表于 2016-5-10 09:36
一个 虚拟主机 配置文件中可以写多个if rewrite 吗?
为什么我写完 访问网站 会出现提示 你多次重定向 打 ...

估计是你写成死循环了     你把你写的rewrite  内容复制 贴出来 我看看 =。=   

正则表达式这部分看完没?
0

乐橙306

赞同来自:

chao901103 发表于 2016-5-10 09:36
一个 虚拟主机 配置文件中可以写多个if rewrite 吗?
为什么我写完 访问网站 会出现提示 你多次重定向 打 ...

我是这么写的

[root@niaoyun-6 vhosts]# cat 80port.conf
server

{
    listen 80;
    server_name www.sundong.wang www.sundong.xyz;
    index index.html index.htm index.php;
    root /opt/nginx/html;

    if ($host != 'www.sundong.wang' ) {
        rewrite  ^/(.*)$  http://www.sundong.wang/$1  permanent;
    }

}
[root@niaoyun-6 vhosts]#

  1. [root@niaoyun-6 vhosts]# curl  -I  www.sundong.xyz
  2. HTTP/1.1 301 Moved Permanently
  3. Server: nginx
  4. Date: Tue, 10 May 2016 02:06:59 GMT
  5. Content-Type: text/html
  6. Content-Length: 178
  7. Connection: keep-alive
  8. Location: http://www.sundong.wang/

  9. [root@niaoyun-6 vhosts]# curl  -v  --head  www.sundong.xyz
  10. * About to connect() to www.sundong.xyz port 80
  11. *   Trying 118.192.147.6... connected
  12. * Connected to www.sundong.xyz (118.192.147.6) port 80
  13. > HEAD / HTTP/1.1
  14. > User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
  15. > Host: www.sundong.xyz
  16. > Accept: */*
  17. >
  18. < HTTP/1.1 301 Moved Permanently
  19. HTTP/1.1 301 Moved Permanently
  20. < Server: nginx
  21. Server: nginx
  22. < Date: Tue, 10 May 2016 02:07:02 GMT
  23. Date: Tue, 10 May 2016 02:07:02 GMT
  24. < Content-Type: text/html
  25. Content-Type: text/html
  26. < Content-Length: 178
  27. Content-Length: 178
  28. < Connection: keep-alive
  29. Connection: keep-alive
  30. < Location: http://www.sundong.wang/
  31. Location: http://www.sundong.wang/

  32. * Connection #0 to host www.sundong.xyz left intact
  33. * Closing connection #0
  34. [root@niaoyun-6 vhosts]#
0

chao901103

赞同来自:

一出现从次重写 ,我就把想另外一个方法了    昨天有出现
0

乐橙306

赞同来自:

chao901103 发表于 2016-5-10 14:21
一出现从次重写 ,我就把想另外一个方法了    昨天有出现

1.你的问题 解决没?
2.你说的这句话 我没看懂 =。=
0

chao901103

赞同来自:

乐橙306 发表于 2016-5-10 15:45
1.你的问题 解决没?
2.你说的这句话 我没看懂 =。=

解决了,后续还会用到,到时候 要请求你了!
0

乐橙306

赞同来自:

chao901103 发表于 2016-5-10 18:37
解决了,后续还会用到,到时候 要请求你了!

你这学习http 入魔的节奏啊     发请求前   需要提前建立连接  完成三次握手吗  =。=  {:4_118:}

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: