腾讯云Centos下Nginx反向代理Apache+Tomcat

1. 安装Apahce, PHP, MySQL以及php连接mysql库的组件
#yum -y install httpd php mysql mysql-server php-mysql     //这里“-y”参数表示静默安装,不会出现提示及交互

2. 安装apache扩展
#yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql

3. 安装php的常用扩展
#yum -y install php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc

4. 安装MySQL的扩展
#yum -y install mysql-connector-odbc mysql-devel libdbi-dbd-mysql

5. 配置开机启动服务
#/sbin/chkconfig httpd on     [设置apache  httpd服务开机启动]

安装nginx
yum install nginx
iptables -I INPUT  -p tcp --dport 80 -j ACCEPT
 
 
关于目录
tomcat6相关
配置目录 /etc/tomcat6
工程目录 /var/lib/tomcat6
 
apache的配置文件是/etc/httpd/conf下
modules放在/usr/lib/httpd下
项目目录 /var/www
 
php的配置文件在/etc/php.d/下 和/etc/php.ini
php的modules放在/usr/lib/php/modules下
 
nginx 
配置/etc/nginx
1.备份 /etc/nginx/conf.d/default.conf
编辑/etc/nginx/conf.d/default.conf
upstream tomcat{
    server localhost:8081;
}
server {
    listen      80;
    server_name     tom.yourdomain.cn;
    location / {
        proxy_pass      http://tomcat;
        proxy_redirect      off;
        proxy_set_header    Host $host;
        proxy_set_header    X-Real-IP $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
    }
 
}
 
upstream apache_index{
        server localhost:9080;
}
server {
        listen          80;
        server_name     www.yourdomain.cn;
        location / {
                proxy_pass              http://apache_index;
                proxy_redirect          off;
                proxy_set_header        Host $host;
                proxy_set_header        X-Real-IP $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        }
 
}
 
upstream apache_blog{
        server localhost:9090;
}
server {
        listen          80;
        server_name     blog.yourdomain.cn;
        location / {
                proxy_pass              http://apache_blog;
                proxy_redirect          off;
                proxy_set_header        Host $host;
                proxy_set_header        X-Real-IP $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        }
 
}
upstream apache_bbs{
        server localhost:9095;
}
server {
        listen          80;
        server_name     bbs.yourdomain.cn;
        location / {
                proxy_pass              http://apache_bbs;
                proxy_redirect          off;
                proxy_set_header        Host $host;
                proxy_set_header        X-Real-IP $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        }
 
}
 
 
tomcat配置
1./etc/tomcat6/server.xml
端口 <Connector port="8081" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" />
默认项目
<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">
        <Context path="" docBase="ContactSys" reloadable="true" debug="0" privileged="true">
        </Context>
 
 
apache
1.备份 /etc/httpd/conf/httpd.conf
停止监听80

Listen 9080
Listen 9090
Listen 9095

 
NameVirtualHost localhost:9080
 
<VirtualHost localhost:9080>
    #ServerAdmin yourname@yourdomain.cn
    DocumentRoot "/home/username/www/index"
    #ServerName blog.yourdomain.cn 
    ErrorLog "/home/username/www/errors/index-error.log"
    CustomLog "/home/username/www/errors/index-access.log" common
        #<Directory />
        #       Options FollowSymLinks
        #       AllowOverride None
        #</Directory>
        <Directory "/home/username/www/index/">
                Options Indexes FollowSymLinks MultiViews
                AllowOverride none
                Order allow,deny
                Allow from all
        </Directory>
</VirtualHost>
NameVirtualHost localhost:9090
 
<VirtualHost localhost:9090>
    #ServerAdmin yourname@yourdomain.cn
    DocumentRoot "/home/username/www/blog"
    #ServerName blog.yourdomain.cn 
    ErrorLog "/home/username/www/errors/blog-error.log"
    CustomLog "/home/username/www/errors/blog-access.log" common
        #<Directory />
        #       Options FollowSymLinks
        #       AllowOverride None
        #</Directory>
        <Directory "/home/username/www/blog/">
                Options Indexes FollowSymLinks MultiViews
                AllowOverride none
                Order allow,deny
                Allow from all
        </Directory>
</VirtualHost>
 
NameVirtualHost localhost:9095
 
<VirtualHost localhost:9095>
    #ServerAdmin yourname@yourdomain.cn
    DocumentRoot "/home/username/www/bbs"
    #ServerName blog.yourdomain.cn 
    ErrorLog "/home/username/www/errors/bbs-error.log"
    CustomLog "/home/username/www/errors/bbs-access.log" common
        #<Directory />
        #       Options FollowSymLinks
        #       AllowOverride None
        #</Directory>
        <Directory "/home/username/www/bbs/">
                Options Indexes FollowSymLinks MultiViews
                AllowOverride none
                Order allow,deny
                Allow from all
        </Directory>
</VirtualHost>
2.DocumentRoot  设置权限 777 chmod 777 -R  D

 

posted @ 2016-12-21 00:22  tla001  阅读(1008)  评论(0编辑  收藏  举报
个人网站 www.tla001.cn