tomcat 实现二级域名 请高手赐教!

eagle1984 2009-02-11 04:16:36
我们要上一个新的文章系统,要求在同一个工程下用二级域名实现。在服务器端配置指向没有问题,现在问题是怎么设计程序?请有过这个经验的前辈们支招!
...全文
455 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
believefym 2009-02-17
  • 打赏
  • 举报
回复
你这个不是二级域名吧
系统信息 2009-02-17
  • 打赏
  • 举报
回复
mark一下,学习了
wipe_tear 2009-02-17
  • 打赏
  • 举报
回复
学习,帮顶
liu_zhaoqf 2009-02-17
  • 打赏
  • 举报
回复
mark
eagle1984 2009-02-16
  • 打赏
  • 举报
回复
#


ThreadsPerChild 250
MaxRequestsPerChild 0


ServerRoot "E:/apache"


Listen 80



LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
LoadModule asis_module modules/mod_asis.so
LoadModule auth_basic_module modules/mod_auth_basic.so
#LoadModule auth_digest_module modules/mod_auth_digest.so
#LoadModule authn_anon_module modules/mod_authn_anon.so
#LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authn_file_module modules/mod_authn_file.so
#LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule autoindex_module modules/mod_autoindex.so
#LoadModule cern_meta_module modules/mod_cern_meta.so
LoadModule cgi_module modules/mod_cgi.so
#LoadModule dav_module modules/mod_dav.so
#LoadModule dav_fs_module modules/mod_dav_fs.so
#LoadModule deflate_module modules/mod_deflate.so
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
#LoadModule expires_module modules/mod_expires.so
#LoadModule file_cache_module modules/mod_file_cache.so
#LoadModule headers_module modules/mod_headers.so
LoadModule imagemap_module modules/mod_imagemap.so
LoadModule include_module modules/mod_include.so
#LoadModule info_module modules/mod_info.so
LoadModule isapi_module modules/mod_isapi.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
#LoadModule mime_magic_module modules/mod_mime_magic.so
#LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
#LoadModule speling_module modules/mod_speling.so
#LoadModule status_module modules/mod_status.so
#LoadModule unique_id_module modules/mod_unique_id.so
LoadModule userdir_module modules/mod_userdir.so
#LoadModule usertrack_module modules/mod_usertrack.so
#LoadModule vhost_alias_module modules/mod_vhost_alias.so
#LoadModule ssl_module modules/mod_ssl.so

# 'Main' server configuration

ServerAdmin shiguoying@yeah.net


ServerName localhost:80


DocumentRoot "E:/apache/htdocs"


<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Satisfy all
</Directory>
<Directory "e:\tomcat5.5\webapps">
Options FollowSymLinks
AllowOverride None
</Directory>

<Directory "E:/apache/htdocs">

Options Indexes FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None

#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all

</Directory>


<IfModule dir_module>
DirectoryIndex index.html
</IfModule>



<FilesMatch "^\.ht">
Order allow,deny
Deny from all
</FilesMatch>


ErrorLog logs/error.log


LogLevel warn

<IfModule log_config_module>

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common

<IfModule logio_module>
# You need to enable mod_logio.c to use %I and %O
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>


CustomLog logs/access.log common


</IfModule>

<IfModule alias_module>

ScriptAlias /cgi-bin/ "E:/apache/cgi-bin/"

</IfModule>


<Directory "E:/apache/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>



DefaultType text/plain

<IfModule mime_module>

AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz




</IfModule>

#
# The mod_mime_magic module allows the server to use various hints from the
# contents of the file itself to determine its type. The MIMEMagicFile
# directive tells the module where the hint definitions are located.
#
#MIMEMagicFile conf/magic

#
# Customizable error responses come in three flavors:
# 1) plain text 2) local redirects 3) external redirects
#
# Some examples:
#ErrorDocument 500 "The server made a boo boo."
#ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 http://localhost/subscription_info.html
#

#
# EnableMMAP and EnableSendfile: On systems that support it,
# memory-mapping or the sendfile syscall is used to deliver
# files. This usually improves server performance, but must
# be turned off when serving from networked-mounted
# filesystems or if support for these functions is otherwise
# broken on your system.
#
#EnableMMAP off
#EnableSendfile off

# Supplemental configuration
#
# The configuration files in the conf/extra/ directory can be
# included to add extra features or to modify the default configuration of
# the server, or you may simply copy their contents here and change as
# necessary.

# Server-pool management (MPM specific)
#Include conf/extra/httpd-mpm.conf

# Multi-language error messages
#Include conf/extra/httpd-multilang-errordoc.conf

# Fancy directory listings
#Include conf/extra/httpd-autoindex.conf

# Language settings
#Include conf/extra/httpd-languages.conf

# User home directories
#Include conf/extra/httpd-userdir.conf

# Real-time info on requests and configuration
#Include conf/extra/httpd-info.conf

# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

# Local access to the Apache HTTP Server Manual
#Include conf/extra/httpd-manual.conf

# Distributed authoring and versioning (WebDAV)
#Include conf/extra/httpd-dav.conf

# Various default settings
#Include conf/extra/httpd-default.conf

# Secure (SSL/TLS) connections
#Include conf/extra/httpd-ssl.conf
#
# Note: The following must must be present to support
# starting without SSL on platforms with no /dev/random equivalent
# but a statically compiled-in mod_ssl.
#
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
#设置Apache与Tomcat之间的连接,让Apache遇到jsp文件时,在后台将其交由Tomcat去处理

LoadModule jk_module modules/mod_jk-1.2.27-httpd-2.2.10.so

JkWorkersFile conf/workers.properties
JkMountFile conf/uriworkermap.properties
JkLogFile logs/mod_jk.log
JkLogLevel warn

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.tongcun\.net$
RewriteRule ^(.+) /$1 [L]

RewriteCond %{HTTP_HOST} [^.]+\.tongcun\.net$
#RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
#RewriteRule ([^.]+)\.tongcun\.net(.*) /$1$2
RewriteRule ([^.]+)\.tongcun\.net(.*) www.baidu.com
eagle1984 2009-02-16
  • 打赏
  • 举报
回复
我们这个需要添加好多的二级域名呢,所以不能每个二级域名都建立一个应用吧?
所以我想把这些二级域名对应的文件夹放到主工程的目录下,请问可不可以?
如果可以,怎么在apache或者tomcat中配置呢?
Jacky_Zhu_1983 2009-02-11
  • 打赏
  • 举报
回复
- -! 汗死
那你的问题问错了啊~~
你域名配置好了...
你的问题这样解决...
在WEBROOT下
abc 放一个文件夹里

bcd 放一个文件夹里

要访问abc里面的页面就要
book.domain.com/abc 这样访问了
>_<
eagle1984 2009-02-11
  • 打赏
  • 举报
回复
我要实现这样的
book.domain.com/abc
book.domain.com/bcd
其中book为书籍类别,abc和bcd是书籍分类比如:计算机,财务,文学。。。

以后可能要添加news.domain.com/shehui,news.domain.com/sports等等

我不知道怎么设计这个程序。在用相同的代码的情况下(只是添加一类news数据),就可以实现不同的二级访问。

不知道我说的是不是清楚!
Jacky_Zhu_1983 2009-02-11
  • 打赏
  • 举报
回复
那你域名配置好了。..不知道程序还要做什么...
直接启动程序 地址栏里就可以用域名拉 还有什么要做的?
eagle1984 2009-02-11
  • 打赏
  • 举报
回复
怎么看不懂你的配置啊?能不能说的详细点。在tomcat中配置二级域名我可以实现。就是不知道程序中怎么实现?不是要配置两个应用吧?
Jacky_Zhu_1983 2009-02-11
  • 打赏
  • 举报
回复
在WEB-INF
下加个XML
比如jboss-web.xml

<?xml version='1.0' encoding='UTF-8' ?>



<!DOCTYPE jboss-web

PUBLIC "-//JBoss//DTD Web Application 2.3V2//EN"

"http://www.jboss.org/j2ee/dtd/jboss-web_3_2.dtd">



<jboss-web>

<context-root>/</context-root>

<virtual-host>www.jacky.com</virtual-host>

</jboss-web>
Jacky_Zhu_1983 2009-02-11
  • 打赏
  • 举报
回复
tomcat 下的server.xml

<Engine name="jboss.web" defaultHost="localhost">
下增加host 比如
<Host name="www.jacky.com"

autoDeploy="false" deployOnStartup="false" deployXML="false">



<Alias>jacky.com</Alias>

<Alias>*.jacky.com</Alias>



<!-- Access logger -->

<!-- -->

<Valve className="org.apache.catalina.valves.AccessLogValve"

prefix="yourdomain_access_log." suffix=".log"

pattern="common" directory="${jboss.server.home.dir}/log"

resolveHosts="true" />

<Valve className="org.jboss.web.tomcat.tc5.jca.CachedConnectionValve"

cachedConnectionManagerObjectName="jboss.jca:service=CachedConnectionManager"

transactionManagerObjectName="jboss:service=TransactionManager" />



<!-- Default context parameters -->

<DefaultContext cookies="true" crossContext="true" override="true"/>



</Host>

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧