lamp+nginx代理+discuz+wordpress+phpmyadmin搭建二

8.[root@lanp ~]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf(添加三个虚拟主机,并把80端口改成88)

<VirtualHost *:88>

    #ServerAdmin [email protected]

    DocumentRoot "/data/bbs"

    ServerName bbs.abc.com

    #ServerAlias www.dummy-host.example.com

    ErrorLog "logs/bbs.abc.com-error_log"

    CustomLog "logs/bbs.abc.com-access_log" common

</VirtualHost>

<VirtualHost *:88>

    #ServerAdmin [email protected]

    DocumentRoot "/data/blog"

    ServerName blog.abc.com

    ErrorLog "logs/blog.abc.com-error_log"

    CustomLog "logs/blog.abc.com-access_log" common

</VirtualHost>

<VirtualHost *:88>

    #ServerAdmin [email protected]

    DocumentRoot "/data/pma"

    ServerName pma.abc.com

    ErrorLog "logs/pma.abc.com-error_log"

    CustomLog "logs/pma.abc.com-access_log" common

</VirtualHost>

检查配置文件是否有语法错误:

[root@lanp ~]# /usr/local/apache2/bin/apachectl -t

Syntax OK

检查88端口是否监听

[root@lanp ~]# /usr/local/apache2/bin/apachectl restart

[root@lanp ~]# netstat -lnp

9.在真机win上的host文件里绑定ip和虚拟主机域名(host文件路径:C/windows/System32/drivers/etc/hosts

192.168.137.107  bbs.abc.com blog.abc.com pma.abc.com

10.安装discuz

在浏览器访问bbs.abc.com/install/,会出现discuz图形安装界面,点我同意,出现很多目录不可写,为啥不可写呢?因为ps aux |grep httpd,httpd是以daemon用户运行。所以需要把discuz中不可写的目录的属主和属组改成daemon,chown -R daemon:daemon config/ data uc_client/data uc_server/data

回到浏览器刷新,下一步,再全新安装discuz

在mysql中创建discuz库并授权一个用户

mysql> create database discuz;

mysql> grant all on *.* to 'aming'@'192.168.137.107' identified by 'aminglinux.com';

mysql> flush privileges;

回到discuz浏览器,数据库名为discuz,数据库用户名为aming,数据库密码aminglinux.com

到此discuz论坛安装完毕


11.安装wordpress

在mysql中创建blog库

mysql> create database blog;

在浏览器中访问blog.abc.com:88进行安装

wKiom1Z6BiTyW7WFAAD-3ngXLGQ414.png

wKioL1Z6BpCgPiOFAACoGpzpWh0238.png

wKioL1Z6BtyTw6RNAAFCOO6tOT8790.png

根据错误提示,在blog目录下创建wp-config.php然后把浏览器中方框内信息拷贝至wp-config.php目录

wKiom1Z6CBnRdAiNAADBOHv5XPc189.png

wKioL1Z6CGHgba_rAACyc_jO0E4925.png

12.安装phpmyadmin

cp libraries/config.default.php config.inc.php

更改

$cfg['Servers'][$i]['user'] = 'root';

$cfg['Servers'][$i]['password'] = 'yourrootpassword';

$cfg['Servers'][$i]['host'] = 'yourdbip';

$cfg['Servers'][$i]['auth_type'] = 'config';##认证模式

在浏览器中访问pma.abc.com:88进行安装

wKioL1Z6CODB7p1QAAF22irg7yQ953.png

wKioL1Z6CQTxjriJAAE0l_DHbrA286.png

wKiom1Z6CTGjCNR4AAHYLn4lYgw017.png


13.安装nginx

[root@lanp src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz

[root@lanp src]# tar zxvf nginx-1.6.2.tar.gz

[root@lanp nginx-1.6.2]# ./configure   --prefix=/usr/local/nginx   --with-pcre

make &make install

nginx启动脚本和配置文件

vim /etc/init.d/nginx  //加入如下内容

#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings

NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"

start() {
        echo -n $"Starting $prog: "
        mkdir -p /dev/shm/nginx_temp
        daemon $NGINX_SBIN -c $NGINX_CONF
        RETVAL=$?
        echo
        return $RETVAL
}

stop() {
        echo -n $"Stopping $prog: "
        killproc -p $NGINX_PID $NGINX_SBIN -TERM
        rm -rf /dev/shm/nginx_temp
        RETVAL=$?
        echo
        return $RETVAL
}

reload(){
        echo -n $"Reloading $prog: "
        killproc -p $NGINX_PID $NGINX_SBIN -HUP
        RETVAL=$?
        echo
        return $RETVAL
}

restart(){
        stop
        start
}

configtest(){
    $NGINX_SBIN -c $NGINX_CONF -t
    return 0
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload)
        reload
        ;;
  restart)
        restart
        ;;
  configtest)
        configtest
        ;;
  *)
        echo $"Usage: $0 {start|stop|reload|restart|configtest}"
        RETVAL=1
esac
exit $RETVAL

chmod 755 /etc/init.d/nginx

chkconfig --add nginx

chkconfig nginx on

service nginx start

service nginx configtest(检测配置文件,configtest相当于-t)

vim /usr/local/nginx/conf/nginx.conf 清空原来的配置,加入如下内容

user nobody nobody;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
    use epoll;
    worker_connections 6000;
}
http

{
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 3526;
    server_names_hash_max_size 4096;
    log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
    '$host "$request_uri" $status'
    '"$http_referer" "$http_user_agent"';
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 30;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    connection_pool_size 256;
    client_header_buffer_size 1k;
    large_client_header_buffers 8 4k;
    request_pool_size 4k;
    output_buffers 4 32k;
    postpone_output 1460;
    client_max_body_size 10m;
    client_body_buffer_size 256k;
    client_body_temp_path /usr/local/nginx/client_body_temp;
    proxy_temp_path /usr/local/nginx/proxy_temp;
    fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
    fastcgi_intercept_errors on;
    tcp_nodelay on;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;
    gzip_comp_level 5;
    gzip_http_version 1.1;
    gzip_types text/plain application/x-javascript text/css text/htm application/xml;

   include vhosts/*.conf;

}


cd /usr/local/nginx/conf/

 mkdir vhosts

touch discuz.conf

touch pma.conf

touch blog.conf


14.discuz.conf

  1. server

  2. {

  3.     listen 80;

  4.     server_name bbs.abc.com;

  5.     index index.html index.htm index.php;

  6.     root /data/bbs;


  7. #根据user_agent控制

  8.     if ($http_user_agent ~ 'bingbot/2.0|MJ12bot/v1.4.2|Spider/3.0|YoudaoBot|Tomato|Gecko/20100315'){

  9.             return 403;

  10.     }

  11.     location ~ admin.php {

  12.         allow 192.168.31.141;

  13.         deny all;

  14.         proxy_pass   http://127.0.0.1:88;

  15.         proxy_set_header Host   $host;

  16.     }


  17.     location ~ \.php$ {

  18.          proxy_pass   http://127.0.0.1:88;

  19.          proxy_set_header Host   $host;

  20.          proxy_set_header X-Real-IP      $remote_addr;

  21.          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  22.     }



  23.     location ~ .*\.(js|css)?$

  24.     {

  25.           expires      24h;

  26.           access_log off;

  27.     }


  28.     location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$ {

  29.          expires 7d;

  30.          valid_referers none blocked server_names *.abc.com *.a.com *.b.com *.baidu.com\

  31.          *.google.com *.google.cn *.soso.com ;

  32.          if ($invalid_referer) {

  33.               return 403;

  34.               #rewrite ^/ http://www.example.com/nophoto.gif;

  35.          }

  36.          access_log off;

  37.     }


  38.     rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;

  39.         rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;

  40.         rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;

  41.         rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;

  42.         rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;

  43.         rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last;



  44.     access_log /home/logs/discuz.log combined_realip;

检测nginx配置文件:/usr/local/nginx/sbin/nginx -t

重启nginx:service nginx restart

在浏览器访问bbs.abc.com,是可以正常进入discuz页面的。


15.blog.conf配置(参考  http://www.upupw.net/nginxhelp/n33.html)

  1. server

  2. {

  3.     listen 80;

  4.     server_name blog.abc.com;

  5.     index index.html index.htm index.php;

  6.     root /data/blog;

  7.     location /wp-admin/ {

  8.         allow 127.0.0.1;

  9.         deny all;

  10.         location ~ \.php$ {

  11.         proxy_pass   http://127.0.0.1:88;

  12.         proxy_set_header Host   $host;

  13.         }

  14.     }


  15.     location  / {

  16.          proxy_pass   http://127.0.0.1:88/;

  17.          proxy_set_header Host   $host;

  18.          proxy_set_header X-Real-IP      $remote_addr;

  19.          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  20.     }


  21. }


检测nginx配置文件是否有语法错误:/usr/local/nginx/sbin/nginx -t

重启nginx:service nginx restart

在浏览器访问:blog.abc.com,是可以访问的


16.配置pma.conf

  1. server

  2. {

  3.     listen 80;

  4.     server_name pma.abc.com;

  5.     index index.html index.htm index.php;

  6.     root /data/pma;


  7.     location / {

  8.          auth_basic              "Auth";

  9.          auth_basic_user_file   /usr/local/nginx/conf/htpasswd;


  10.     location ~ \.php$ {

  11.          proxy_pass   http://127.0.0.1:88;

  12.          proxy_set_header Host   $host;

  13.          proxy_set_header X-Real-IP      $remote_addr;

  14.          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  15.     }


  16.     }

  17. }

检测nginx配置文件是否有语法错误:/usr/local/nginx/sbin/nginx -t

重启nginx:service nginx restart

浏览器访问:pma.abc.com是可以访问到的


17、配置nginx的日志切割

[root@lanp vhosts]# vim /usr/local/sbin/logrotate.sh

#!/bin/bash

d=`date -d "-1 day" +%Y%m$d`

/bin/mv /home/logs/discuz.log /home/logs/discuz_$d.log

/etc/init.d/nginx reload >/dev/null 2>/dev/null

cd /home/logs

gzip discuz_$d.log


18、mysql备份脚本

vim mysqlbak.sh

#!/bin/bash

source /etc/profile

d=`date +%F`

/usr/local/mysql/bin/mysqldump -uroot -p838024 wordpress >/data/mysqlbak/$d.wordpresssql

/usr/local/mysql/bin/mysqldump -uroot -p838024 discuz >/data/mysqlbak/$d.discuzsql

/usr/local/mysql/bin/mysqldump -uroot -p838024 phpmyadmin >/data/mysqlbak/$d.phpmyadminsql

rsync -avLuPz -e "ssh -p 22" /data/mysqlbak/ 192.168.137.107:/tmp/

再把脚本放进crontab计划任务

chmod a+x mysqlbak.sh

crontab -e

*/3 * * * * /root/shell/mysqlbak.sh


你可能感兴趣的:(Blog,common,虚拟主机)