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

schema://host[:port#]/path/.../[?query-string][#anchor]

时间:2016-08-05 14:01:12      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:

1:http协议状态
200 OK
最常见的就是成功响应状态码200了, 这表明该请求被成功地完成,所请求的资源发送回客户端

302 Found
重定向,新的URL会在response 中的Location中返回,浏览器将会自动使用新的URL发出新的Request
例如在IE中输入, http://www.google.com. HTTP服务器会返回302, IE取到Response中Location header的新URL, 又重新发送了一个Request.

304 Not Modified
代表上次的文档已经被缓存了, 还可以继续使用,
例如打开博客园首页, 发现很多Response 的status code 都是304

400 Bad Request  客户端请求与语法错误,不能被服务器所理解
403 Forbidden 服务器收到请求,但是拒绝提供服务
404 Not Found
请求资源不存在(输错了URL)
比如在IE中输入一个错误的URL, http://www.cnblogs.com/tesdf.aspx

500 Internal Server Error 服务器发生了不可预期的错误
503 Server Unavailable 服务器当前不能处理客户端的请求,一段时间后可能恢复正常
502 Bad gateway


2:http服务器控制浏览器缓存
应用场景:某手机web应用。目的:帮助消耗某运营商流量 

默认情况下浏览器会对请求内容缓存 首次response 返回200 表示请求成功,当第二次在请求这个页面时候 如图片,css等会根据max生存时间及etag值判断缓存是否过期,如不过期就返回304,使用缓存
这就与消耗流量的目的相违背,为了达到目的需要在服务器发给客户端的http包头上告诉浏览器不要缓存任何内容,每次刷新都新请求

关于http具体的详细过程,cnblogs有一篇不错的文件 http://www.cnblogs.com/TankXiao/archive/2012/11/28/2793365.html 感谢,其中介绍的fiddler2是个不错的工具
然后nginx的配置也有一篇不错的文章http://blog.sina.com.cn/s/blog_5dc960cd0100hxr7.html 感谢

结合这些文章,我在nginx.conf中加了如下配置
location ~ \.(htm|html|gif|jpg|jpeg|png|bmp|ico|css|js)$
               {
                  add_header Cache-Control no-store;
                  add_header Cache-Control private;
               }
重启后,用fiddler2观察,所有请求状态返回码均是200,没有出现304,达到了效果,只是害了用户流量,amen!!!

3:nginx 出现no input file
出现这种情况大部分在用fastcgi解析php,最根本的原因是nginx传给fastcgi的参数(scritpname,script_filename)出错,导致出现弱404(跟传统404稍不同)或者no input file

前提:在nginx.conf中root指令可以定义在server,location段,如果没有没有在任何段定义root,root默认为/path/to/install/html,如/usr/local/nginx/html,nginx在遇到php文件
会交给fastcgi执行,这个转交过程需要nginx告诉fastcgi一些环境运行变量,如cgi version,server software,最重要的是要告诉fastcgi要执行的php路径,SCRIPT_FILENAME,
SCRIPT_NAME,DOCUMENT_URI,DOCUMENT_ROOT,这些变量取得root要么是默认html,要么是写在处理php的location里面的
server {
    index index.php index.html;
    root /www/;
    server_name test.com;
location /a/
{
  root  /test/;
}
location ~ .*\.php?$
 {
        try_files $uri = /50x.html;
         include fastcgi.conf;
         fastcgi_pass 127.0.0.1:9000;
         fastcgi_index index.php;
      }

}
此时访问http://test.com/a/index.html,实际访问路径为http://test.com/test/a/index.html 访问正常
如果你访问http://test.com/a/index.php ,不正常,此时就出现了no input file或者是弱404,因为nginx实际访问路径为http://test.com/www/a/index.php
此时www没有a这个目录,要解决此问题可以在
location ~ .*\.php?$
 {
        root /test;
         try_files $uri = /50x.html;
         include fastcgi.conf;
         fastcgi_pass 127.0.0.1:9000;
         fastcgi_index index.php;
   }
上述做法是不建议的,因为在处理php的时候一般不可能值处理某个目录下的php,还有一点就是location之间定义的root不能相互继承,所以 php的location
不能使用test 的location root,继承了server级别的root

建议正确配置nginx的方法

在server级别定义root,如果要引用其他目录非root目录,建议使用软连接,软连接被应用目录到root下,如下

1:URL http://test.com:8080/a/index.html 
  I):如果a目录在www目录下,那么上述URL访问html,php完全正常
  II):如果a目录不在www目录下,需要做个软连接 ln -s /path/to/a  /www/a
2:配置文件如下
server 
{
     listen 8080;
     server_name test.com; \\可以定义根据主机头的虚拟主机,主机头
     index index.php index.html;
     root  /www;
     location ~ .*\.php?$
      {
         try_files $uri = /50x.html;   
         
         include fastcgi.conf;
         fastcgi_pass 127.0.0.1:9000;
         fastcgi_index index.php;
      } 
}
URL URI区别 见
schema://host[:port#]/path/.../[?query-string][#anchor]

scheme               指定低层使用的协议(例如:http, https, ftp)
host                   HTTP服务器的IP地址或者域名
port#                 HTTP服务器的默认端口是80,这种情况下端口号可以省略。如果使用了别的端口,必须指明,例如 http://www.cnblogs.com:8080/
path                   访问资源的路径
query-string       发送给http服务器的数据
anchor-             锚


3:nginx proxy_pass 的proxy_hearder的一些变量
      proxy_redirect          off;
       proxy_set_header        Host $host;
       proxy_set_header        X-Real-IP $remote_addr;
       proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_pass http://19

 

http://blog.chinaunix.net/uid-24443760-id-3590539.html

schema://host[:port#]/path/.../[?query-string][#anchor]

标签:

原文地址:http://www.cnblogs.com/softidea/p/5740915.html

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