免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 9966 | 回复: 7
打印 上一主题 下一主题

[Web] nginx为什么在二级目录访问的时候要加/才能访问到(已解决) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-02-01 00:14 |只看该作者 |倒序浏览
nginx为什么在二级目录访问的时候要加/才能访问到
比如http://www.domain.com/dir
要这样http://www.domain.com/dir/才能访问到
不加最后那个/无法访问。

配置文件

  1. user  vmail vmail;
  2. worker_processes  10;

  3. #error_log  logs/error.log;
  4. #error_log  logs/error.log  notice;
  5. #error_log  logs/error.log  info;

  6. #pid        logs/nginx.pid;


  7. events {
  8.     worker_connections  51024;
  9.     use kqueue;
  10. }


  11. http {
  12.     include       conf/mime.types;
  13.     include       conf/fastcgi.conf;
  14.     default_type  application/octet-stream;

  15.     #log_format  main  '$remote_addr - $remote_user [$time_local] $request '
  16.     #                  '"$status" $body_bytes_sent "$http_referer" '
  17.     #                  '"$http_user_agent" "$http_x_forwarded_for"';

  18.     #access_log  logs/access.log  main;

  19.     client_header_timeout  3m;

  20.     client_body_timeout    3m;
  21.     send_timeout           3m;

  22.     client_header_buffer_size    1k;
  23.     large_client_header_buffers  4 4k;

  24.     gzip on;
  25.     gzip_min_length  1100;
  26.     gzip_buffers     4 8k;
  27.     gzip_types       text/plain;

  28.     output_buffers   1 32k;
  29.     postpone_output  1460;

  30.     sendfile         on;
  31.     tcp_nopush       on;
  32.     tcp_nodelay      on;
  33.     send_lowat       12000;

  34.     keepalive_timeout  75 20;


  35.     server {
  36.         listen       80;
  37.         server_name  localhost;

  38.         #charset koi8-r;

  39.         #access_log  logs/host.access.log  main;

  40.         location / {
  41.             root   html;
  42.             index  index.html index.htm index.php;
  43.         }

  44.         #error_page  404              /404.html;

  45.         # redirect server error pages to the static page /50x.html
  46.         #
  47.         #error_page   500 502 503 504  /50x.html;
  48.         #location = /50x.html {
  49.         #    root   html;
  50.         #}

  51.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  52.         #
  53.         #location ~ \.php$ {
  54.         #    proxy_pass   [url]http://127.0.0.1[/url];
  55.         #}

  56.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  57.         #
  58.         location ~ \.php$ {
  59.             fastcgi_pass   127.0.0.1:9000;
  60.             fastcgi_index  index.php;
  61.         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
  62.         #    include        conf/fastcgi_params;
  63.         }

  64.         location /NginxStatus {
  65.             stub_status             on;
  66.             access_log              on;
  67.         }

  68.         # deny access to .htaccess files, if Apache's document root
  69.         # concurs with nginx's one
  70.         #
  71.         #location ~ /\.ht {
  72.         #    deny  all;
  73.         #}
  74.     }


  75.     # another virtual host using mix of IP-, name-, and port-based configuration
  76.     #
  77.     #server {
  78.     #    listen       8000;
  79.     #    listen       somename:8080;
  80.     #    server_name  somename  alias  another.alias;

  81.     #    location / {
  82.     #        root   html;
  83.     #        index  index.html index.htm;
  84.     #    }
  85.     #}


  86.     # HTTPS server
  87.     #
  88.     #server {
  89.     #    listen       443;
  90.     #    server_name  localhost;

  91.     #    ssl                  on;
  92.     #    ssl_certificate      cert.pem;
  93.     #    ssl_certificate_key  cert.key;

  94.     #    ssl_session_timeout  5m;

  95.     #    ssl_protocols  SSLv2 SSLv3 TLSv1;
  96.     #    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
  97.     #    ssl_prefer_server_ciphers   on;

  98.     #    location / {
  99.     #        root   html;
  100.     #        index  index.html index.htm;
  101.     #    }
  102.     #}

  103. }
复制代码

[ 本帖最后由 scyzxp 于 2008-2-1 14:13 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2008-02-01 11:52 |只看该作者
我用apache和nginx做了对比试验
在二级目录访问的时候,apache是IE自动把/加上去的,而nginx不能做到。
可以参考一下这个网站关于Location的部分内容:
http://wiki.codemongers.com/NginxHttpCoreModule#location

也许能找到答案,希望对你有帮助^_^

111.jpg (12.34 KB, 下载次数: 63)

111.jpg

论坛徽章:
0
3 [报告]
发表于 2008-02-01 13:47 |只看该作者
原帖由 adu119 于 2008-2-1 11:52 发表
我用apache和nginx做了对比试验
在二级目录访问的时候,apache是IE自动把/加上去的,而nginx不能做到。
可以参考一下这个网站关于Location的部分内容:
http://wiki.codemongers.com/NginxHttpCoreModule#lo ...


首先感谢你,我看了半天还是没有找到答案,希望有人能找到解记办法

论坛徽章:
0
4 [报告]
发表于 2008-02-01 14:13 |只看该作者
原帖由 scyzxp 于 2008-2-1 13:47 发表


首先感谢你,我看了半天还是没有找到答案,希望有人能找到解记办法



自己解决了。多谢各位的关注

论坛徽章:
0
5 [报告]
发表于 2008-07-07 07:48 |只看该作者

如何解决的说说

如何解决的?

论坛徽章:
0
6 [报告]
发表于 2008-09-14 18:00 |只看该作者
我也想知道,大虾,回个贴啊

论坛徽章:
0
7 [报告]
发表于 2008-09-16 12:42 |只看该作者
怎么解决的?

论坛徽章:
0
8 [报告]
发表于 2008-09-16 15:39 |只看该作者
默认配置当你访问http://abc.example.com/dir 时不会加”/”

常见做法

  1.       if (-d $request_filename){
  2.   rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
  3.       }
复制代码


更佳的替代方法

optimize_server_names off;#优化服务器名称:关
server_name_in_redirect off;#服务器名称重定向:关

http://wiki.codemongers.com/Ngin ... timize_server_names
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP