美文网首页
apache2.2配置多站点及在apache2上部署java

apache2.2配置多站点及在apache2上部署java

作者: HeJD | 来源:发表于2018-04-19 15:34 被阅读0次

    apache2路径:

    适用于apache2.2

    主路径:/usr/local/apache2
    配置:.../conf/httpd.conf
    

    配置多站点:

    通过不同端口配置多站点:

    1、在httpd.conf中监听多个端口

    # Listen: Allows you to bind Apache to specific IP addresses and/or
    # ports, instead of the default. See also the <VirtualHost>
    # directive.
    #
    # Change this to Listen on specific IP addresses as shown below to 
    # prevent Apache from glomming onto all bound IP addresses.
    #
    #Listen 12.34.56.78:80
    Listen 80
    Listen 82
    

    2、设置虚拟主机
    在httpd.conf中添加

    1.
    Alias / 'PROJECT_ROOT'
    <VirtualHost *:80>
        DocumentRoot 'PROJECT_ROOT'
        ServerName localhost:80或域名
        //设置文件夹权限
        <Directory 'PROJECT_ROOT'>
            Options Indexes FollowSymLinks
            AllowOverride None
            Order deny,allow
            Allow from all
        </Directory>
    </VirtualHost>
    
    2.
    <VirtualHost *:82>
        DocumentRoot 'PROJECT_ROOT'
        ServerName localhost:82或域名
        Alias /static/ "PROJECT_ROOT/static/"
        Alias /media/ "PROJECT_ROOT/media/"
        //python使用wsgi
        WSGIScriptAlias / /home/fengxikang/bgi_pet/bgi_pet/wsgi.py
        //权限设置
        <Directory "PROJECT_ROOT">
            <Files wsgi.py>
                Require all granted
            </Files>
            Options +ExecCGI
            Order allow,deny
            Allow from all
        </Directory>
    </VirtualHost>
    

    同一端口,不同域名:

    修改虚拟主机中的 ServerName即可,端口可以监听同一端口

    1.
    <VirtualHost *:80>
    ...
    ServerName www.a.com
    ...
    </VirtualHost>
    
    2.
    <VirtualHost *:80>
    ...
    ServerName www.b.com
    ...
    </VirtualHost>
    

    同一端口,同一域名,不同路径

    Alias / 'PROJECT_ROOT'
    <VirtualHost *:80>
        DocumentRoot 'PROJECT_ROOT'
        ServerName localhost:80或域名
        //设置文件夹权限
        <Directory 'PROJECT_ROOT'>
            Options Indexes FollowSymLinks
            AllowOverride None
            Order deny,allow
            Allow from all
        </Directory>
    </VirtualHost>
    

    设置顶部的Alias,使其指向不同路径,如

    1.
    Alias /a 'PROJECT_ROOT'+a_ROOT
    <VirtualHost *:80>
    ...
    </VirtualHost>
    
    2.
    Alias /b 'PROJECT_ROOT'+b_ROOT
    <VirtualHost *:80>
    ...
    </VirtualHost>
    

    访问时,使用子目录访问,如
    localhost/a
    localhost/b
    就能够访问到不同的站点

    apache2+jkmount+tomcat

    1、下载JKMount,编译,得到mod_jk.so文件,将mod_jk.so复制到apache2/modules下
    并在httpd.conf中添加

    LoadModule jk_module modules/mod_jk.so
    

    2、在apache2/conf/下创建workers.properties用以分发

    worker.list=worker01,worker02.....
    worker.worker01.type=ajp13
    worker.worker01.host=localhost
    //这个port并不是tomcat默认的8080,需要在tomcat的配置文件中查看
    worker.worker01.port=8009
    worker.worker01.lbfactor=50
    #worker.worker01.cachesize=10
    #worker.worker01.cache_timeout=600
    worker.worker01.socket_keepalive=1
    worker.worker01.socket_timeout=300 
    worker.worker01.connection_pool_size=1000
    worker.worker01.connection_pool_timeout=600
    

    3、在apache2/conf/下创建mod_jk.conf加载配置
    名字可以自由发挥,只要在httpd.conf中被include就可以
    httpd.conf

    Include conf/mod_jk.conf
    

    mod_jk.conf

    JkWorkersFile conf/workers.properties
    //此处要在logs中创建相应的文件,否则会报错
    JkLogFile logs/mod_jk.log
    JkLogLevel info
    
    #Select the log format
    JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
    
    # JkOptions indicate to send SSL KEY SIZE,
    JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
    
    # JkRequestLogFormat set the request format
    JkRequestLogFormat "%w %V %T"
    

    最后,设置httpd.conf

    <VirtualHost *:80>
        //此处的PROJECT_ROOT在tomcat的webapps的相关项目下
        DocumentRoot "PROJECT_ROOT"
        ServerName 域名
        ServerAlias 域名别名
        //将该ServerName下的所有内容转发到JkMount的worker01处理
        JkMount /* worker01
        //权限设置
        <Directory "PROJECT_ROOT">
            Options Indexes FollowSymLinks
            AllowOverride None
            Order deny,allow
            Allow from all
        </Directory>
    </VirtualHost>
    

    注意事项

    1.提示无法加载wsgi modules时,需添加python的site-packages路径WSGIPythonPath /usr/local/lib/python2.7/site-packages

    编译安装JKMount

    以下内容引用自http://www.w2bc.com/Article/15945

    下载

    apr-1.5.2.tar.gz
    apr-util-1.5.4.tar.gz
    pcre-8.36.tar.gz
    tomcat-connectors-1.2.42-src.tar.gz
    

    apr

    tar -zxf apr-1.5.2.tar.gz
    cd apr-1.5.2
    ./configure --prefix=/usr/local/apr  
    make && make install
    

    apr-util

    tar -zxf apr-util-1.5.4.tar.gz
    cd apr-util-1.5.4
    ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config  
    make && make install
    

    pcre

    tar -zxf pcre-8.36.tar.gz
    cd pcre-8.36
    ./configure --prefix=/usr/local/pcre  
    make && make install
    

    编译生成mod_jk

    tar -zxf tomcat-connectors-1.2.42-src.tar.gz
    cd tomcat-connectors-1.2.42-src/native
    ./configure --with-apxs=/usr/local/apache2/bin/apxs
    make
    chmod 777 ./apache-2.0/mod_jk.so
    cp ./apache-2.0/mod_jk.so /usr/local/apache2/modules/
    

    至此将mod_jk.so复制到apache2/modules下,可在httpd.conf中load

    相关文章

      网友评论

          本文标题:apache2.2配置多站点及在apache2上部署java

          本文链接:https://www.haomeiwen.com/subject/vytvcftx.html