lamp 配置



有时候,我们需要给一些特殊的访问设置一个用户认证机制,增加安全。
比如我们刚刚安装好的discuz论坛,是有一个管理后台的,虽然管理后台本身就有密码,
但我们为了更加安全,可以再设置一层用户认证。
# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
在对应的虚拟主机配置中加入如下配置:

<Directory /data/www/admin.php>
AllowOverride AuthConfig
AuthName "alksdjflkasjdf"
AuthType Basic
AuthUserFile /data/.htpasswd
require valid-user
</Directory>

# /usr/local/apache2/bin/htpasswd -cm /data/.htpasswd 123123

/usr/local/apache2/bin/apachectl graceful



设置默认主机

<VirtualHost *:80>
DocumentRoot "/tmp/tmp"
ServerName tmp.com
</VirtualHost>
创建配置中提到的目录 # mkdir /tmp/tmp chmod 600 /tmp/tmp
这时候,我们用ip去访问
Forbidden


301跳转
跳转用到一个模块 rewrite

# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
在对应的虚拟主机配置文件中加入
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.aaa.com$
RewriteRule ^/(.*)$ http://www.bbb.com/$1 [R=301,L]
</IfModule>

RewriteCond条件
RewriteRule 规则


<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.aaa.com [OR]
RewriteCond %{HTTP_HOST} ^www.bbb.net$
RewriteRule ^/(.*)$ http://www.ccc.com/$1 [R=301,L]
</IfModule>




日志切割
在对应的虚拟主机配置文件中加入
ErrorLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/aaa-error_%Y%m%d.log 86400"
CustomLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/aaa-access_%Y%m%d.log 86400" combined

来源ip 用户 时间 动作
h l u t \r\ %>s %b \ referer




不记录指定文件类型日志

SetEnvIf Request_URI ".*\.gif$" image-request
SetEnvIf Request_URI ".*\.jpg$" image-request
SetEnvIf Request_URI ".*\.png$" image-request
SetEnvIf Request_URI ".*\.bmp$" image-request
SetEnvIf Request_URI ".*\.swf$" image-request
SetEnvIf Request_URI ".*\.js$" image-request
SetEnvIf Request_URI ".*\.css$" image-request

CustomLog "|/usr/local/apache/bin/rotatelogs -l /usr/local/apache/logs/oem.discuz.qq.com-access_%Y%m%d.log 86400" combined env=!image-request

Request_URI 变量名
image-request 目的是为了不记忆它在 CustomLog 的配置后面加上env=!image-request




配置静态缓存
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType image/gif "access plus 1 days"
ExpiresByType image/jpeg "access plus 24 hours"
ExpiresByType image/png "access plus 24 hours"
ExpiresByType text/css "now plus 2 hour"
ExpiresByType application/x-javascript "now plus 2 hours"
ExpiresByType application/javascript "now plus 2 hours"
ExpiresByType application/x-shockwave-flash "now plus 2 hours"
ExpiresDefault "now plus 0 min"
</IfModule>

curl -x127.0.0.1:80 http://www.test.com/static/image/common/logo.png -I

使用expires模块


配置防盗链
SetEnvIfNoCase Referer "^http://.*\.aaa\.com" local_ref
SetEnvIfNoCase Referer ".*\.bbb\.com" local_ref
SetEnvIfNoCase Referer "^$" local_ref
<filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif)">
Order Allow,Deny
Allow from env=local_ref
</filesmatch>



访问控制
<Directory "/data/www">
AllowOverride None
Options None
Order allow,deny
Allow from all
Deny from 127.0.0.1
</Directory>


<filesmatch "(.*)admin(.*)">
Order deny,allow
Deny from all
Allow from 127.0.0.1
Allow from 2.2.2.2
</filesmatch>


网站的图片会放在 /date/www/date/attachment/froum/ 里面

php 禁止解析 为安全考虑
<Directory /data/www/data>
php_admin_flag engine off 关闭php引擎的就这一行
<filesmatch "(.*)php"> 如果没有下面的一段配置 那么用户会把文件给下载走的
Order deny,allow
Deny from all
</filesmatch>
</Directory>




禁止指定user_agent
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^*curl* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^*chrome* [NC]
RewriteRule .* - [F] 禁止
</IfModule>

NC 忽略大小写
crul -A 模仿user_agent -xip:80 www.aaa.com/froum.php -I


Apache通过rewrite限制某个目录
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^.*/tmp/* [NC]
RewriteRule .* - [F]
</IfModule>

php.ini
常用的配置
1

禁用的函数
disable_functions = eval,assert,popen,passthru,escapeshellarg,escapeshellcmd,passthru,exec,system,chroot,scandir,chgrp,chown,escapeshellcmd,escapeshellarg,shell_exec,proc_get_status,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,leak,popepassthru,stream_socket_server,popen,proc_open,proc_close

2
状态码为500时 大部分是php配置程序有问题

display_errors = off 如果打开 出现错误的时候浏览器界面会显示白页 状态码为500

让log_errors = on
error_log=/path/to/logfile
error_reporting = E_ALL | E_STRICT

在搜索 error_log = /usr/local/php/logs/php_errors.log
在配置日志的格式 级别
error_reporting = E_ALL & ~ E_NOTTCE


3
限制用户只能访问的目录
open_basedir = /data/www:/tmp
也可以在Apache里面配置
比如
php_admin_value open_basedir "/data/www/:/tmp/"



进入相应的源码包下
/usr/local/src/httpd-2.2.24/modules/filters


执行
/usr/local/apache2/bin/apxs -i -c -a mod_include.c

ls /usr/local/apache2/modules/
httpd.exp libphp5.so mod_deflate.so mod_expires.so mod_include.so mod_rewrite.so

加载成功




php增加模块
cd /usr/local/src/php-5.3.27/ext/curl

执行
/usr/local/php/bin/phpize

目的为了生成config文件
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install

[root@localhost curl]# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/

cp modules/curl.so /usr/local/php/ext/

编辑php.ini文件
找到
extension_dir = "/usr/local/php/ext"

找到
extension=curl.so
加载完成

apache加入chkconfig


cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd

vim /etc/init.d/httpd
在第一行#!/bin/sh下增加两行文字
# chkconfig: 35 70 30
# description: Apache


保存退出
chmod 755 /etc/init.d/httpd
chkconfig --level 35 httpd on


开启慢查询日志
只要超过一秒就去查询
long_query_time = 1
log_slow_queries = /data/mysql/slow.log


posted @ 2016-12-16 16:23  onlylc  阅读(118)  评论(0)    收藏  举报