« POP3协议命令原始码及工作原理 | 首 页 | 『The Legend of 1900』 《海上钢琴师》 »

2005 年 05 月 16 日

SSH 和 Apache 1.3 的一些积累

| 分类: 服务器技术 Server Tech. |

最近在用 Miracle Linux, 所以碰到了一些老版本的问题,在这里把 ssh 和 apache 1.3.33 的问题汇总一下,做个备份。

  • ssh 远程登陆不能用 root 登陆的解决方法。 Miracle Linux 是 Red Hat 的一个 customized 版本,专门为 ORACLE 度身定做的。rpm 包安装好后会安上 ssh,但是远程用户不能用 root 直接登陆,也不能通过 su - 登陆。查了一下,修改 configure 文件即可:
    修改文件: /etc/ssh/sshd_config
    修改选项: PermitRootLogin = yes
    重启ssh:service sshd restart
  • Apache 1.3.33 目录最后的不添加反斜杠问题。
    问题说明: 
     例如目录 http://www.kreny.com/doc/
    在 address bar 里面输入了 http://www.kreny.com/doc 后,不会自动转为 http://www.kreny.com/doc/
    我的解决方法:
    在 apache 2.0 中有一个关于这个在目录后自动添加反斜杠的模块,只要编译了这个模块即可顺利解决这个问题。在 apache 1.3 中我试着用 rewreite rules 来解决这个问题。当然这是个苯方法,必须把需要转意的目录一个一个写到 httpd.conf 文件里面。在此仅仅作为对 rewrite rules 的一个练习吧!

    Rewrite Rules

    RewriteEngine on
    RewriteRule ^/kd$ /kd/ [R]

资料: 《Trailing Slash Problem》
出处: Apache 1.3 URL Rewriting Guide

英文版本
----------------------------------------
Trailing Slash Problem
Description:
Every webmaster can sing a song about the problem of the trailing slash on URLs referencing directories. If they are missing, the server dumps an error, because if you say /~quux/foo instead of /~quux/foo/ then the server searches for a file named foo. And because this file is a directory it complains. Actually is tries to fix it themself in most of the cases, but sometimes this mechanism need to be emulated by you. For instance after you have done a lot of complicated URL rewritings to CGI scripts etc.
Solution:
The solution to this subtle problem is to let the server add the trailing slash automatically. To do this correctly we have to use an external redirect, so the browser correctly requests subsequent images etc. If we only did a internal rewrite, this would only work for the directory page, but would go wrong when any images are included into this page with relative URLs, because the browser would request an in-lined object. For instance, a request for image.gif in /~quux/foo/index.html would become /~quux/image.gif without the external redirect!
So, to do this trick we write:

RewriteEngine on
RewriteBase /~quux/
RewriteRule ^foo$ foo/ [R]

The crazy and lazy can even do the following in the top-level .htaccess file of their homedir. But notice that this creates some processing overhead.

RewriteEngine on
RewriteBase /~quux/
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [R]

中文版本
----------------------------------------
后缀斜杠的问题
说明:
每个网管对引用目录后缀斜杠的问题都有一本苦经,如果遗漏了,服务器会产生一个错误,因为如果请求是/~quux/foo而不是/~quux/foo/,服务器会去找一个叫foo的文件,而它是一个目录,所以就报错了。事实上,大多数情况下,它自己会试图修正这个错误,但是有时候需要你手工纠正,比如,在重写了许多CGI脚本中的复杂的URL以后。

方案:
解决这个微妙问题的方案是让服务器自动添加后缀的斜杠。对此,必须使用一个外部的重定向,使浏览器正确地处理后继的对诸如图片的请求。如果仅仅作一个内部的重写,可能只对目录页面有效,而对内嵌有使用相对URL的图片的页面则无效,因为浏览器有请求内嵌目标的可能。比如,如果不用外部重定向,/~quux/foo/index.html页面中对image.gif的请求,其结果将是/~quux/image.gif!。

所以,应该这样写:

RewriteEngine on RewriteBase /~quux/ RewriteRule ^foo$ foo/ [R]

又懒又疯狂的做法是把这些写入其宿主目录中的顶级.htaccess中,但是须注意,如此会带来一些处理上的开销。

RewriteEngine on
RewriteBase /~quux/
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [R]

(END)

评论 (2 条)

kicker:

kicker
2005年09月04日 06:19

为了解决apache服务器地址最后斜杠的问题,Google到了你的网页。但是最后我是这么解决的:
在httpd.conf文件中,以下两行动一下:
ServerName your.host.name
UseCanonicalName On
然后apachectl restart就可以了.

tom:

tom
2007年04月26日 17:53

rewrite 后面目录后面加入 / 还真是需要.

谢谢!


发表评论

(如果您还为在此成功留言,也许是因为需要管理员逐一审核留言内容后放可看到您的评论。请稍后并感谢您的耐心等待。)

阅览更多文章请访问 首页过去的存档