2015-05-18lamp/lnmp阶段复习

我们以模拟实际需求的形式来复习。需求如下:
1. 准备两台centos 6,其中一台机器跑mysql,另外一台机器跑apache和nginx + php 
2. 同时安装apache和nginx,其中nginx启动80端口,用来跑静态对象(图片、js、css),apache监听88端口,负责跑动态页(php相关的),并且需要由nginx代理对外访问
3. mysql服务器需要开启慢查询日志
4. 搭建discuz、wordpress以及phpmyadmin,域名分别为bbs.abc.com, blog.abc.com, pma.abc.com
5. 配置discuz的伪静态(nginx)
6. apache不需要记录日志,nginx记录日志,但不记录图片等静态页的日志,并且配置日志切割
7. 配置图片防盗链(nginx)
8. 配置图片缓存7天,js,css缓存1天(nginx)
9. discuz和wordpress访问后台限制一下ip白名单,比如只允许192.168.1.100访问(nginx)
10. phpmyadmin整个站点需要配置用户认证(nginx)
11. 写一个mysql备份的脚本,每天5点执行,需要远程拷贝到web机器上
12. 把除了百度、google外的其他常见搜索引擎蜘蛛封掉,比如(bingbot/2.0、Sogou web spider/4.0、360Spider、YisouSpider、YandexBot/3.0)(nginx)
参考配置:
/usr/local/apache2/conf/extra/httpd-vhosts.conf

  1. NameVirtualHost *:88
  2. <VirtualHost *:88>
  3.     DocumentRoot "/tmp/tmp"
  4.     ServerName tmp.com
  5.     php_admin_value open_basedir "/tmp/tmp"
  6. <Directory /tmp/tmp/>
  7.       Order allow,deny
  8.       Deny from all
  9. </Directory>
  10. </VirtualHost>
  11. <VirtualHost *:88>
  12.     DocumentRoot "/data/bbs"
  13.     ServerName bbs.abc.com
  14. </VirtualHost>
  15. <VirtualHost *:88>
  16.     DocumentRoot "/data/blog"
  17.     ServerName blog.abc.com
  18. </VirtualHost>
  19. <VirtualHost *:88>
  20.     DocumentRoot "/data/pma"
  21.     ServerName pma.abc.com
  22. </VirtualHost>

复制代码

nginx相关的:
1. bbs.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;
  45. }

复制代码

2. 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. }

复制代码

3. 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. }

复制代码

phpmyadmin 安装 http://www.aminglinux.com/bbs/thread-6509-1-1.html

Wordpress     安装 http://www.apelearn.com/bbs/forum.php?mod=viewthread&tid=7954&highlight=wordpress

你可能感兴趣的:(mysql,wordpress,服务器,图片,discuz)