这里给出我对两种方案的配置,我使用了iptables来实现端口重发,加入的规则如下
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
iptables -A FORWARD -p tcp --destination-port 80 --destination 10.20.10.204 -j ACCEPT
iptables -t nat -A PREROUTING -d 1.2.3.4 -p tcp -m tcp --dport 80 -j DNAT --to-destination 10.20.10.204:80
iptables -t nat -A POSTROUTING -s 10.20.10.0/8 -d 10.20.10.204 -p tcp -m tcp --dport 80 -j SNAT --to-source 10.20.10.208
不知道什么原因,我的这个配置没有成功,以后再解决它。
对于apche的重写规则,其实也是比较容易的,需要修改如下地方:
在这里我们假定
DocumentRoot "/var/www/html"
ServerRoot "/etc/httpd"
1) /etc/httpd/conf/httpd.conf 文件
# 加载 rewrite 模块
LoadModule rewrite_module modules/mod_rewrite.so
<Directory />
# 允许符号连接和覆盖,否则rewrite不起作用
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory "/var/www/html">
# 允许符号连接和覆盖,否则rewrite不起作用
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
2) 在 /var/www/html 下新建 .htaccess 文件,内容如下
RewriteEngine on
RewriteBase /
RewriteRule ^forum$ forum/ [L]
3) 在 /var/www/html 下创建 forum 文件加,在forum文件夹中创建 .htaccess 文件,内容如下
RewriteEngine on
RewriteBase /forum/
RewriteRule (.*) http://web_server_ip/$1 [P,L]
需要注意的是,在上面的RewriteRule当中一定要写上 [P] 标示,表示是内部重定向, [R]表示是外部重定向。 我就是因为没有写上P标识,耽误了好长时间。
然后重启httpd服务,就可以通过 http://nat_server/forum 来访问web_server上面提供的论坛服务了。