配置nginx 日志切割
修改日志格式
log_format combined_realip '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" ';
如果,你使用了代理,那么日志格式为:
log_format combined_realip '$http_x_forwarded_for - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" ';
下载awstats 软件
wget http://cdnetworks-kr-1.dl.source ... awstats-6.95.tar.gz
或者:http://www.ypl.cc/attachments/month_1011/awstats-6.95.tar.gz
tar zxvf awstats-6.95.tar.gz
安装 awstats
mv awstats-6.95 /usr/local/awstats
cd /usr/local/awstats/tools
创建一个新的统计
./awstats_configure.pl
-----> Check for web server install
Enter full config file path of your Web server.
Example: /etc/httpd/httpd.conf
Example: /usr/local/apache2/conf/httpd.conf
Example: c:\Program files\apache group\apache\conf\httpd.conf
Config file path ('none' to skip web server setup):
#> none #因为我们这里用的是 Nginx,所以写 none,跳过。
回车
Your web server config file(s) could not be found.
You will need to setup your web server manually to declare AWStats
script as a CGI, if you want to build reports dynamically.
See AWStats setup documentation (file docs/index.html)
-----> Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf'
File awstats.model.conf updated.
-----> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ?
#> y #y 创建一个新的统计配置
回车
-----> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.ypl.cc
Example: demo
Your web site, virtual server or profile name:
#> www.ypl.cc #统计网站的域名 例:
www.ypl.cc
回车 -----> Define config file path
In which directory do you plan to store your config file(s) ?
Default: /etc/awstats
Directory path to store config file(s) (Enter for default):
#>
使用默认直接回车,接下来便会出现以下的提示 ----> Add update process inside a scheduler
Sorry, configure.pl does not support automatic add to cron yet.
You can do it manually by adding the following command to your cron:
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.ypl.cc
#回头把该命令填入crontab 按指定时间执行
Or if you have several config files and prefer having only one command:
/usr/local/awstats/tools/awstats_updateall.pl now
Press ENTER to continue... 回车继续
A SIMPLE config file has been created: /etc/awstats/awstats.www.ypl.cc.conf
#新配置文件所在的路径
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'www.ypl.cc' with command:
> perl awstats.pl -update -config=www.ypl.cc
You can also build static report pages for 'www.ypl.cc' with command:
> perl awstats.pl -output=pagetype -config=www.ypl.cc
Press ENTER to finish...
~ 匹配,区分大小写
~* 不区分大小写的匹配
!~ 不匹配
!~* 不匹配
^~ 常用于location 语法中,后边是一个字符串。它的意思是,在这个字符串匹配后停止进行正则表达式的匹配。
如: location ^~ /images/,你希望对/images/这个目录进行一些特别的操作,如增加expires头,防盗链等,但是你又想把除了这个目录的图片外的所有图片只进行增加expires头的操作,这个操作可能会用到另外一个location,例如:location ~* \.(gif|jpg|jpeg)$,这样,如果有请求/images/1.jpg,nginx如何决定去进行哪个location中的操作呢?结果取决于标识符^~,如果你这样写:location /images/,这样nginx会将1.jpg匹配到location ~* \.(gif|jpg|jpeg)$这个location中,这并不是你需要的结果,而增加了^~这个标识符后,它在匹配了/images/这个字符串后就停止搜索其它带正则的location。
= 表示精确的查找地址,如location = /它只会匹配uri为/的请求,如果请求为/index.html,将查找另外的location,而不会匹配这个,当然可以写两个location,location = /和location /,这样/index.html将匹配到后者,如果你的站点对/的请求量较大,可以使用这个方法来加快请求的响应速度。
@ 表示为一个location进行命名,即自定义一个location,这个location不能被外界所访问,只能用于Nginx产生的子请求,主要为error_page和try_files。
这个选项是用来配置是否长连接的,其实原理和apache是一样的,关于apache中keepalive 相关设置请参考 http://mylinux.5d6d.com/thread-919-1-1.html
但是nginx中的该参数没有on与off的开关,只能去设置超时的时间长短。默认如果不设置该参数的话,系统会设置为75s。
当设置为
keepalive_timeout 0;
此时就关闭了长连接。不妨简单测试一下:
curl -I -v http://localhost:80
结果为:
HTTP/1.1 200 OK
< Server: nginx/1.0.0
Server: nginx/1.0.0
< Date: Tue, 29 Nov 2011 04:25:24 GMT
Date: Tue, 29 Nov 2011 04:25:24 GMT
< Content-Type: text/html; charset=gb2312
Content-Type: text/html; charset=gb2312
< Connection: close
Connection: close
< X-Powered-By: PHP/5.2.8
X-Powered-By: PHP/5.2.8
* Closing connection #0这里的 Connection状态为 close,意思是已经关闭连接。
当设置为
keepalive_timeout 10;
再次
curl -I -v http://localhost:80
结果为:
HTTP/1.1 200 OK
< Server: nginx/1.0.0
Server: nginx/1.0.0
< Date: Tue, 29 Nov 2011 04:27:31 GMT
Date: Tue, 29 Nov 2011 04:27:31 GMT
< Content-Type: text/html; charset=gb2312
Content-Type: text/html; charset=gb2312
< Connection: keep-alive
Connection: keep-alive
< X-Powered-By: PHP/5.2.8
X-Powered-By: PHP/5.2.8
* no chunk, no close, no size. Assume close to signal end
<
* Closing connection #0这里的connection 状态为 keep-alive
至于,如何配置这个参数呢?这主要看你网站的访问量以及内容,就像是在 http://mylinux.5d6d.com/thread-919-1-1.html 这篇帖子中提及的,分三种情况吧。
但是,本人还是建议你设置为0,即关闭长连接。
server {
listen 80;
server_name www.aldjflas.cn;
access_log /home/logs/bbs/access.log combined buffer=32k;
error_log /home/logs/bbs/error.log warn;
location / {
index index.html index.htm index.php;
root /data/www/wwwroot/bbs;
}
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|thumb) {
root /data/www/wwwroot/bbs;
access_log off;
expires 10d;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/dev/shm/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www/wwwroot/bbs$fastcgi_script_name;
}
}
nginx的日志格式中,有一个字段叫做 $http_user_agent 这个其实是客户端浏览器的一个信息,比如咱们平时使用IE浏览器的话,nginx的日志中会记录类似于这样的信息:
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
这一段信息就是 $http_user_agent 了。咱们可以根据这个特点来控制客户端的请求访问。比如,现在有这样一个需求
把使用IE 6.0 的客户端禁止访问,我们可以这样做:
在nignx的配置文件中,加入
location / {
if ($http_user_agent ~ 'MSIE 6.0'){
return 403;
}
}这样就能禁止使用IE 6.0的客户端访问服务器。
upstream web.home.org {
server 192.168.1.10:80 weight=1;
server 192.168.1.11:80 weight=2;
server 192.168.1.12:80;
server 192.168.1.13:80;
}
upstream squid.home.org {
server 192.168.1.117:80;
server 192.168.1.118:80;
server 192.168.1.119:80;
}
server {
listen 80;
server_name www.home.org;
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;
location / {
root html;
index index.html index.htm;
if ($request_uri ~* ".*\.(js|css|gif|jpg|jpeg|png|bmp|swf|html)$")
{
proxy_pass http://squid.home.org;
}
if ($request_uri ~* "^/view/(.*)$")
{
proxy_pass http://squid.home.org;
}
proxy_pass http://web.home.org;
}
location /Status {
stub_status on;
access_log on;
}
linux + nginx + mysql + php memcache扩展, eaccelerator 扩展。
[hide][/hide]
如果不想下载,在线看教程吧 http://mylinux.5d6d.com/study/17.htm
思路: 把论坛附件部分的访问分离到另一个域名走缓存(CDN)
问题: 朋友的discuz!论坛由于附件(图片)很多,所以引入了CDN,但是接入CDN后,可能是因为缓存(代理)的原因而产生了诸多问题,影响较大的一个就是“评分时,会出现 您的请求来路不正确,无法提交 这样的错误提示”。鉴于此,想到了把论坛的附件给分离出来走另外一个域名,而cdn去缓存另外的域名即可。
解决问题: 既然有了想法,那么就去实施了。
论坛域名为 www.123.com 附件的访问路径诸如 www.123.com/attachments/.....jpg
1. 配置虚拟主机,根目录为论坛的 attachemens (附件所在目录), 域名为 att.123.com
2. 配置www.123.com 虚拟主机中的rewrite规则
if ($request_filename ~* attachments) {
rewrite ^/attachments/(.*)$ http://att.123.com/attachments/$1 permanent;
}
3. att.123.com 走cdn
参考资料 :http://blog.c1gstudio.com/archives/434
安装Apache
# useradd -M www -s /sbin/nologin (增加 Apache运行账户)
# cd /usr/local/src/
# tar zvxf httpd-2.2.11.tar.bz2
# cd httpd-2.2.11
# ./configure --prefix=/usr/local/apache2 \
--with-included-apr \
--enable-so \
--enable-deflate=shared \
--enable-expires=shared \
--enable-rewrite=shared \
--enable-static-support \
--disable-userdir
# make
# make install
在tomcat的安装目录logs下,会有manager,catalina,localhost,host-manager开头的日志文件,每天都生成一个,很讨厌的,如果不想要这些日志,可以这样处理,编辑tomcat安装目录下的conf下的logging.properties文件,把含有manager,catalina,localhost,host-manager等字眼的行注释掉就ok了,不过建议catalina的不要注释,这个文件很有用途!
Options -Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Deny from all
本帖最后由 lqph3387 于 2011-1-6 08:41 编辑
一,安装TongWeb5.0应用程序
TongWeb5.0需要在操作系统hosts文件中定义本机IP地址,并以本机的IP优先。如下所示:
192.168.12.1 localhost
127.0.0.1 localhost
[tongweb@app9 ~]$useradd tongweb && su - tongweb
[tongweb@app9 ~]$sh Install_TW5.0.0.0_Linux.bin -i console
在Linux平台上安装TongWeb5.0,出现如下信息:
Preparing to install...
Extracting the installation resources from the installer archive...
Configuring the installer for this system's environment...
Launching installer...
Preparing CONSOLE Mode Installation...
===================================================================TongWeb5.0 (created with InstallAnywhere)
-------------------------------------------------------------------------------
===================================================================License Agreement
-----------------
Installation and Use of TongWeb5.0 Requires Acceptance of the Following License
Agreement:
End user license agreement for Tongtech co., LTD software
The End user license agreement will be accompanied with the products and
related documents of Tongtech co., LTD. Please read it carefully. You will
be asked to accept this license and continue the installation. If you do
not accept this license, you should refuse it and quit the installation.
Grant of license:
Tongtech co., LTD grants you the license to use the software program, but you
must make such assurance as following to our company: Do not
use¡¢copy¡¢modify¡¢rent or convey this system besides the terms listed in this
license and the formal contact signed with Tongtech co., LTD.
You guarantee:
1. Using this software only on a single computer;
2. For the purpose of backup or archival management for the use on one
computer, making copy of this system by machine-reading format.
You guarantee not:
1. Transfer license of this system again.
2. Getting source codes of this system by altering, modifying, translating,
reversing, anti-editing, anti-compiling or any other methods.
PRESS <ENTER> TO CONTINUE:
2. 出现如上信息后,按回车键继续安装。
3. Copy or transfer this software in whole or in part.
When you transfer this software in part or in whole to any third part, your
right to use the software shall terminate immediately and without notice.
The copyright and ownership of this software:
The copyright of this software is owned by Tongtech co., LTD. The structures,
tissues and codes are the most valuable commercial secrets of Tongtech co.,
LTD. This software and documents are protected by national copyright laws and
international treaty provisions. You are not allowed to delete the copyright
notice from this software. You must agree to prohibit any kind of illegal copy
of this software and documents.
Limited warranty:
In the largest permitting area of the law, In no situation shall Tongtech
co., LTD be liable for any special, unexpected, direct or indirect damages
(including, without limitation, damages for loss of business profits, business
interruption, loss of business information, or any other pecuniary loss)
arising out of the use of or inability to use this product and the providing or
inability to provide supporting services, even if Tongtech co., LTD has been
advised of the possibility of such damages.
PRESS <ENTER> TO CONTINUE:
3. 出现如上信息后,按回车键继续安装。
Termination:
Tongtech co., LTD may terminate the license at any time if you violate any
term or condition of the license. When the license is terminated, you must
destroy all copies of the software and all of its documents immediately, or
return them to Tongtech co., LTD.
Law:
"Intelligent Property Protection Regulation", "Copyright Law", "Exclusive Law"
Now, you must have already carefully read and understand this license, and
agreed to obey all the terms and conditions strictly.
DO YOU ACCEPT THE TERMS OF THIS LICENSE AGREEMENT? (Y/N): y
4. 出现如上信息后,请选择是否接受许可条款,若接受请输入y。
===============================================================================
Choose Install Folder
---------------------
Where would you like to install?
Default Install Folder: /home/tongweb/TongWeb5.0
ENTER AN ABSOLUTE PATH, OR PRESS <ENTER> TO ACCEPT THE DEFAULT
: /usr/local/TongWeb5.0
5. 出现如上信息后,请输入安装路径,若同意使用给出的默认安装路径,请按回车键继续安装。
===================================================================
Pre-Installation Summary
------------------------
Please Review the Following Before Continuing:
Product Name:
TongWeb5.0
Install Folder:
/usr/local/TongWeb5.0
Link Folder:
/usr/local/TongWeb5.0
Disk Space Information (for Installation Target):
Required: 139,934,247 bytes
Available: 40,788,152,320 bytes
PRESS <ENTER> TO CONTINUE:
6. 出现如上信息后,请确认预安装信息是否正确,若正确请按回车键继续安装。
===============================================================================
Installing...
-------------
[==================|==================|==================|==================]
[------------------|------------------|------------------|------------------]
===============================================================================
Installation Complete
---------------------
Congratulations. TongWeb5.0 has been successfully installed to:
/usr/local/TongWeb5.0
PRESS <ENTER> TO EXIT THE INSTALLER:
7. 出现如上信息后,表示成功安装产品,按回车键结束安装。
二,安装License
在TongWeb5.0产品光盘中提供有license文件。TongWeb5.0 license文件目前包含如下控制:
1. 版本
2. 有效期
安装方法:将TongWeb5.0产品光盘中的license.dat文件复制到安装完成的TongWeb5.0根目录下。
三,启动TongWeb服务器
TongWeb5.0安装成功后,使用TongWeb5.0_HOME/bin目录下的startserver.sh启动TongWeb5.0应用服务器
[tongweb@app9 ~]$sh /usr/local/TongWeb5.0/bin/startserver.sh &
四,登陆控制台测试
http://IP:9060/twns/ 默认用户名和密码均为twns
五,加入开机自动启动
[tongweb@app9 ~]$echo '/bin/su -c "/usr/local/TongWeb5.0/bin/startserver.sh &" tongweb' >> /etc/rc.local
Apache主配置文件为:/usr/local/apache2/conf/httpd.conf
# vim /usr/local/apache2/conf/httpd.conf
找到:
AddType application/x-gzip .gz .tgz
在该行下面添加
AddType application/x-httpd-php .php
找到:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
将该行改为
<IfModule dir_module>
DirectoryIndex index.html index.htm index.php
</IfModule>
找到:
#Include conf/extra/httpd-mpm.conf
#Include conf/extra/httpd-info.conf
#Include conf/extra/httpd-vhosts.conf
#Include conf/extra/httpd-default.conf
去掉前面的“#”号,取消注释。
一,在sun的官方(https://cds.sun.com/is-bin/INTER ... R@CDS-CDS_Developer) 下载jdk-6u15-linux-i586.bin,上传至/usr/local/src目录
[root@host1 ~]# cd /usr/local/src
[root@host1 src]# chmod a+x jdk-6u15-linux-i586.bin
[root@host1 src]# sh jdk-6u15-linux-i586.bin
此时会出现JDK 安装授权协议。可以一路按Enter浏览,当出现Do you agree to the above license terms? [yes or no] 的字样。输入yes即可
[root@host1 src]# mv jdk1.6.0_15 /opt
二,设置环境变量
[root@host1 src]#vim /etc/profile
在末尾输入以下内容
#set java environment
JAVA_HOME=/opt/jdk1.6.0_15/
JAVA_BIN=/opt/jdk1.6.0_15/bin
JRE_HOME=/opt/jdk1.6.0_15/jre
PATH=$PATH:/opt/jdk1.6.0_15/bin:/opt/jdk1.6.0_15/jre/bin
CLASSPATH=/opt/jdk1.6.0_15/jre/lib:/opt/jdk1.6.0_15/lib:/opt/jdk1.6.0_15/jre/lib/charsets.jar
export JAVA_HOME JAVA_BIN JRE_HOME PATH CLASSPATH
执行命令source /etc/profile,使配置立即生效
[root@host1 src]#source /etc/profile
三,测试
[root@host1 src]# java -version
java version "1.6.0_15"
Java(TM) SE Runtime Environment (build 1.6.0_15-b03)
Java HotSpot(TM) Server VM (build 14.1-b02, mixed mode)
出现以上信息则表示安装成功
- «
- 1
- ...
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- ...
- 63
- »