码迷,mamicode.com
首页 > Web开发 > 详细

Tomcat 及Apache 配置

时间:2018-05-07 17:48:00      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:Tomcat 及Apache 配置

TOMCAT_HOME /conf/server.xml中做如下配置:
<Host name="www.xxx.xxx" appBase="D:\web">
<Context path="/otdr" docBase="D:\web\apps" />
<Context path="/doc" docBase="D:\ecs\LAMP" />
//Context 虚拟目录
</Host>

假如想在tomcat下发布多个网站,则可做如下配置:

Apache的配置 Apache的配置由httpd.conf文件配置,因此下面的配置指令都是在httpd.conf文件中修改。 主站点的配置(基本配置) 基本配置: ServerRoot "/mnt/software/apache2" #你的apache软件安装的位置。其它指定的目录如果没有指定绝对路径,则目录是相对于该目录。 PidFile logs/httpd.pid #第一个httpd进程(所有其他进程的父进程)的进程号文件位置。 Listen 80 #服务器监听的端口号。 ServerName www.clusting.com:80 #主站点名称(网站的主机名)。 ServerAdmin admin@clusting.com #管理员的邮件地址。 DocumentRoot "/mnt/web/clusting" #主站点的网页存储位置。 以下是对主站点的目录进行访问控制: Options FollowSymLinks AllowOverride None Order allow,deny Allow from all AllowOverride:允许存在于.htaccess文件中的指令类型(.htaccess文件名是可以改变的,其文件名由AccessFileName指令决定): None: 当AllowOverride被设置为None时。不搜索该目录下的.htaccess文件(可以减小服务器开销)。 All: 在.htaccess文件中可以使用所有的指令。 Order:控制在访问时Allow和Deny两个访问规则哪个优先: Allow:允许访问的主机列表(可用域名或子网,例如:Allow from 192.168.0.0/16)。 Deny:拒绝访问的主机列表。 DirectoryIndex index.html index.htm index.php #主页文件的设置(本例将主页文件设置为:index.html,index.htm和index.php) StartServers 5 #启动apache时启动的httpd进程个数。 MinSpareServers 5 #服务器保持的最小空闲进程数。 MaxSpareServers 10 #服务器保持的最大空闲进程数。 MaxClients 150 #最大并发连接数。 MaxRequestsPerChild 1000 #每个子进程被请求服务多少次后被kill掉。0表示不限制,推荐设置为1000。 在该工作模式下,服务器启动后起动5个httpd进程(加父进程共6个,通过ps -ax|grep httpd命令可以看到)。当有用户连接时,apache会使用一个空闲进程为该连接服务,同时父进程会fork一个子进程。直到内存中的空闲进程达到MaxSpareServers。该模式是为了兼容一些旧版本的程序。我缺省编译时的选项。 worker:如果httpd -l列出worker.c,则需要对下面的段进行配置: StartServers 2 #启动apache时启动的httpd进程个数。 MaxClients 150 #最大并发连接数。 MinSpareThreads 25 #服务器保持的最小空闲线程数。 MaxSpareThreads 75 #服务器保持的最大空闲线程数。 ThreadsPerChild 25 #每个子进程的产生的线程数。 MaxRequestsPerChild 0 #每个子进程被请求服务多少次后被kill掉。0表示不限制,推荐设置为1000。 该模式是由线程来监听客户的连接。当有新客户连接时,由其中的一个空闲线程接受连接。服务器在启动时启动两个进程,每个进程产生的线程数是固定的(ThreadsPerChild决定),因此启动时有50个线程。当50个线程不够用时,服务器自动fork一个进程,再产生25个线程。 perchild:如果httpd -l列出perchild.c,则需要对下面的段进行配置: NumServers 5 #服务器启动时启动的子进程数 StartThreads 5 #每个子进程启动时启动的线程数 MinSpareThreads 5 #内存中的最小空闲线程数 MaxSpareThreads 10 #最大空闲线程数 MaxThreadsPerChild 2000 #每个线程最多被请求多少次后退出。0不受限制。 MaxRequestsPerChild 10000 #每个子进程服务多少次后被重新fork。0表示不受限制。 该模式下,子进程的数量是固定的,线程数不受限制。当客户端连接到服务器时,又空闲的线程提供服务。 如果空闲线程数不够,子进程自动产生线程来为新的连接服务。该模式用于多站点服务器。 持久性连接设置 KeepAlive On #开启持久性连接功能。即当客户端连接到服务器,下载完数据后仍然保持连接状态。 MaxKeepAliveRequests 100 #一个连接服务的最多请求次数。 KeepAliveTimeout 30 #持续连接多长时间,该连接没有再请求数据,则断开该连接。缺省为15秒。 别名设置 对于不在DocumentRoot指定的目录内的页面,既可以使用符号连接,也可以使用别名。别名的设置如下: Alias /download/ "/var/www/download/" #访问时可以输入:http://www.custing.com/download/ #对该目录进行访问控制设置 Options Indexes MultiViews AllowOverride AuthConfig Order allow,deny Allow from all CGI设置 ScriptAlias /cgi-bin/ "/mnt/software/apache2/cgi-bin/" # 访问时可以:http://www.clusting.com/cgi-bin/ 。但是该目录下的CGI脚本文件要加可执行权限! #设置目录属性 AllowOverride None Options None Order allow,deny Allow from all 个人主页的设置 (public_html) UserDir public_html (间用户的主页存储在用户主目录下的public_html目录下 URL http://www.clusting.com/~bearzhang/file.html 将读取 /home/bearzhang/public_html/file.html 文件) chmod 755 /home/bearzhang #使其它用户能够读取该文件。 UserDir /var/html (the URL http://www.clusting.com/~bearzhang/file.html 将读取 /var/html/bearzhang/file.html) UserDir /var/www/*/docs (the URL http://www.clusting.com/~bearzhang/file.html 将读取 /var/www/bearzhang/docs/file.html) 日志的设置 (1)错误日志的设置 ErrorLog logs/error_log #日志的保存位置 LogLevel warn #日志的级别 显示的格式日下: [Mon Oct 10 15:54:29 2005] [error] [client 192.168.10.22] access to /download/ failed, reason: user admin not allowed access (2)访问日志设置 日志的缺省格式有如下几种: LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined LogFormat "%h %l %u %t "%r" %>s %b" common #common为日志格式名称 LogFormat "%{Referer}i -> %U" referer LogFormat "%{User-agent}i" agent CustomLog logs/access_log common 用户认证的配置 (1)in the httpd.conf: AccessFileName .htaccess Alias /download/ "/var/www/download/" Options Indexes AllowOverride AuthConfig 虚拟主机的配置 (1)基于IP地址的虚拟主机配置 Listen 80 DocumentRoot /www/example1 ServerName www.example1.com DocumentRoot /www/example2 ServerName www.example2.org (2) 基于IP和多端口的虚拟主机配置 Listen 172.20.30.40:80 Listen 172.20.30.40:8080 Listen 172.20.30.50:80 Listen 172.20.30.50:8080 DocumentRoot /www/example1-80 ServerName www.example1.com DocumentRoot /www/example1-8080 ServerName www.example1.com DocumentRoot /www/example2-80 ServerName www.example1.org DocumentRoot /www/example2-8080 ServerName www.example2.org (3)单个IP地址的服务器上基于域名的虚拟主机配置: Listen 80 NameVirtualHost *:80 DocumentRoot /www/example1 ServerName www.example1.com ServerAlias example1.com. *.example1.com # Other directives here DocumentRoot /www/example2 ServerName www.example2.org # Other directives here (4)在多个IP地址的服务器上配置基于域名的虚拟主机: Listen 80 ServerName server.domain.com DocumentRoot /www/mainserver NameVirtualHost 172.20.30.50 DocumentRoot /www/example1 ServerName www.example1.com # Other directives here ... DocumentRoot /www/example2 ServerName www.example2.org # Other directives here ... (5)在不同的端口上运行不同的站点(基于多端口的服务器上配置基于域名的虚拟主机): Listen 80 Listen 8080 NameVirtualHost 172.20.30.40:80 NameVirtualHost 172.20.30.40:8080 ServerName www.example1.com DocumentRoot /www/domain-80 ServerName www.example1.com DocumentRoot /www/domain-8080 ServerName www.example2.org DocumentRoot /www/otherdomain-80 ServerName www.example2.org DocumentRoot /www/otherdomain-8080 (6)基于域名和基于IP的混合虚拟主机的配置: Listen 80 NameVirtualHost 172.20.30.40 DocumentRoot /www/example1 ServerName www.example1.com DocumentRoot /www/example2 ServerName www.example2.org DocumentRoot /www/example3 ServerName www.example3.net SSL加密的配置 (1) conf/ssl.conf 配置文件中的主要参数配置如下: Listen 443 SSLPassPhraseDialog buildin #SSLPassPhraseDialog exec:/path/to/program SSLSessionCache dbm:/usr/local/apache2/logs/ssl_scache SSLSessionCacheTimeout 300 SSLMutex file:/usr/local/apache2/logs/ssl_mutex (2) 创建和使用自签署的证书: a.Create a RSA private key for your Apache server /usr/local/openssl/bin/openssl genrsa -des3 -out /usr/local/apache2/conf/ssl.key/server.key 1024 b. Create a Certificate Signing Request (CSR) /usr/local/openssl/bin/openssl req -new -key /usr/local/apache2/conf/ssl.key/server.key -out /usr/local/apache2/conf/ssl.key/server.csr c. Create a self-signed CA Certificate (X509 structure) with the RSA key of the CA /usr/local/openssl/bin/openssl req -x509 -days 365 -key /usr/local/apache2/conf/ssl.key/server.key -in /usr/local/apache2/conf/ssl.key/server.csr -out /usr/local/apache2/conf/ssl.crt/server.crt /usr/local/openssl/bin/openssl genrsa 1024 -out server.key /usr/local/openssl/bin/openssl req -new -key server.key -out server.csr /usr/local/openssl/bin/openssl req -x509 -days 365 -key server.key -in server.csr -out server.crt (3) 创建自己的CA(认证证书),并使用该CA来签署服务器的证书。 mkdir /CA cd /CA cp openssl-0.9.7g/apps/CA.sh /CA ./CA.sh -newca openssl genrsa -des3 -out server.key 1024 openssl req -new -key server.key -out server.csr cp server.csr newreq.pem ./CA.sh -sign cp newcert.pem /usr/local/apache2/conf/ssl.crt/server.crt cp server.key /usr/local/apache2/conf/ssl.key/

Tomcat 及Apache 配置

标签:Tomcat 及Apache 配置

原文地址:http://blog.51cto.com/jinkaiye/2113607

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