Archive for the ‘ 服务器 ’ Category

什么是SMTP协议?SMTP端口号是多少?什么是SMTP服务器?

SMTP:简单邮件传输协议

(SMTP:Simple Mail Transfer Protocol)

SMTP 是一种提供可靠且有效电子邮件传输的协议。 SMTP 是建模在 FTP 文件传输服务上的一种邮件服务,主要用于传输系统之间的邮件信息并提供来信有关的通知。

SMTP 独立于特定的传输子系统,且只需要可靠有序的数据流信道支持。 SMTP 重要特性之一是其能跨越网络传输邮件,即“ SMTP 邮件中继”。通常,一个网络可以由公用互联网上 TCP 可相互访问的主机、防火墙分隔的 TCP/IP 网络上 TCP 可相互访问的主机,及其它 LAN/WAN 中的主机利用非 TCP 传输层协议组成。使用 SMTP ,可实现相同网络上处理机之间的邮件传输,也可通过中继器或网关实现某处理机与其它网络之间的邮件传输。

在这种方式下,邮件的发送可能经过从发送端到接收端路径上的大量中间中继器或网关主机。域名服务系统(DNS)的邮件交换服务器可以用来识别出传输邮件的下一跳 IP 地址。

SMTP端口号是多少?

25

什么是SMTP服务器?

SMTP是SIMPLE MAIL TRANSFER PROTOCOL的缩写,一般的发信软件,如Outlook Express、FoxMail、Eudora都是使用这个协议进行发信的。如果你的ISP没有提供SMTP服务器,那你就无法使用该协议发送信件。无法从一个邮箱的域名知道它是否提供SMTP服务或者SMTP服务器是什么。如果不知道自己信箱的SMTP服务器,可以向提供信箱的ISP询问。现在为了避免滥发垃圾邮件,许多免费邮件的提供商都不提供SMTP服务器,如Hotmail、eyou,这些免费邮件用户只能登录后通过浏览器发信。收费邮件一般都提供POP3和SMTP服务器

CentOS下如何在防火墙中打开端口

CentOS安装好,默认只打开了22端口,如果希望开放其他端口的话,需要打开所需端口。
比如打开http的默认端口80
编辑iptables
vi /etc/sysconfig/iptables
添加

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3001 -j ACCEPT

重新启动服务

/sbin/service iptables restart

查看端口是否开放
/sbin/iptables -L -n

配置Linux(cent os 5.2)服务器并安装PHP、MySQL、NGINX

此服务器要求支持Zend Framework(同样支持大多数PHP DEV的需求).

转载请著名出处http://www.wemvc.com/535.html

作者:Joshua

时间:2009年3月

前提:安装centos 5.2安装时默认配置就好,配置好网卡,安装系统时自订软件,只安装最基本的工具,Development Library、Development Tool、Editor。

相关站点:

PHP

Official Nginx Site

Nginx Wiki

Official PCRE Site

相关软件:

首先我们要看下Zend Framework官方的的需求。

Table A.1. PHP Extensions Used in Zend Framework by Component

Extension Dependency Type Used by Zend Framework Components
apc Hard Zend_Cache_Backend_Apc
bcmath Soft Zend_Locale
bitset Soft Zend_Search_Lucene
bz2
calendar
com_dotnet
ctype Hard Zend_Auth_Adapter_Http
Zend_Gdata
Zend_Http_Client
Zend_Pdf
Zend_Rest_Client
Zend_Rest_Server
Zend_Search_Lucene
Zend_Uri
Zend_Validate
curl Hard Zend_Http_Client_Adapter_Curl
date
dba
dbase
dom Hard Zend_Feed
Zend_Gdata
Zend_Log_Formatter_Xml
Zend_Rest_Server
Zend_Search_Lucene
Zend_Service_Amazon
Zend_Service_Delicious
Zend_Service_Flickr
Zend_Service_Simpy
Zend_Service_Yahoo
Zend_XmlRpc
exif
fbsql
fdf
filter
ftp
gd Hard Zend_Pdf
gettext
gmp
hash Hard Zend_Auth_Adapter_Http
ibm_db2 Hard Zend_Db_Adapter_Db2
iconv Hard Zend_Currency
Zend_Locale_Format
Zend_Mime
Zend_Pdf
Zend_Search_Lucene
Zend_Service_Audioscrobbler
Zend_Service_Flickr
Zend_XmlRpc_Client
imap
informix
interbase Hard Zend_Db_Adapter_Firebird
json Soft Zend_Json
ldap
libxml Hard DOM
SimpleXML
XSLT
mbstring Hard Zend_Feed
mcrypt
memcache Hard Zend_Cache_Backend_Memcached
mhash
mime_magic Hard Zend_Http_Client
ming
msql
mssql
mysql
mysqli Hard Zend_Db_Adapter_Mysqli
ncurses
oci8 Hard Zend_Db_Adapter_Oracle
odbc
openssl
pcntl
pcre Hard Virtually all components
pdo Hard All PDO database adapters
pdo_dblib
pdo_firebird
pdo_mssql Hard Zend_Db_Adapter_Pdo_Mssql
pdo_mysql Hard Zend_Db_Adapter_Pdo_Mysql
pdo_oci Hard Zend_Db_Adapter_Pdo_Oci
pdo_pgsql Hard Zend_Db_Adapter_Pdo_Pgsql
pdo_sqlite Hard Zend_Db_Adapter_Pdo_Sqlite
pgsql
posix Soft Zend_Mail
pspell
readline
recode
Reflection Hard Zend_Controller
Zend_Filter
Zend_Filter_Input
Zend_Json
Zend_Log
Zend_Rest_Server
Zend_Server_Reflection
Zend_Validate
Zend_View
Zend_XmlRpc_Server
session Hard Zend_Controller_Action_Helper_Redirector
Zend_Session
shmop  
SimpleXML Hard Zend_Config_Xml
Zend_Feed
Zend_Rest_Client
Zend_Service_Audioscrobbler
Zend_XmlRpc
soap Hard Zend_Service_StrikeIron
sockets
SPL Hard Virtually all components
SQLite Hard Zend_Cache_Backend_Sqlite
standard Hard Virtually all components
sybase
sysvmsg
sysvsem
sysvshm
tidy
tokenizer
wddx
xml Hard Zend_Translate_Adapter_Qt
Zend_Translate_Adapter_Tmx
Zend_Translate_Adapter_Xliff
XMLReader
xmlrpc
XMLWriter
xsl
zip
zlib Hard Zend_Pdf
Memcache

php-5.2.5.tar.gz

libxml2-2.6.24.tar.gz (安装php5必须)
curl-7.15.0.tar.gz
libiconv-1.12.tar.gz
libmcrypt-2.5.7.tar.gz
mcrypt-2.6.7.tar.gz

xmlrpc-2.2.1.tar.gz

libedit-0.3.tar.gz

pspell-.12.2.tar.gz

openssl-0.9.8i.tar.gz

gettext-0.17.tar.gz
gd-2.0.35.tar.gz
freetype-2.3.7.tar.gz
jpegsrc.v6b.tar.gz
libpng-1.2.33.tar.gz
zlib-1.2.3.tar.gz

http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.12.tar.gz

libiconv-1.12.tar.gz
ftp://ftp.gnu.org/gnu/gettext/gettext-0.17.tar.gz
http://ftp.gnome.org/pub/GNOME/sources/libxml2/2.6/libxml2-2.6.24.tar.gz
http://curl.haxx.se/download/curl-7.15.0.tar.gz
ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz

http://voxel.dl.sourceforge.net/sourceforge/mcrypt/mcrypt-2.6.7.tar.gz

http://www.libgd.org/releases/gd-2.0.35.tar.gz
http://voxel.dl.sourceforge.net/sourceforge/freetype/freetype-2.3.7.tar.gz
http://www.ijg.org/files/jpegsrc.v6b.tar.gz
http://voxel.dl.sourceforge.net/sourceforge/libpng/libpng-1.2.33.tar.gz
http://www.zlib.net/zlib-1.2.3.tar.gz

http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.12.tar.gz

把以上所有软件包下载到:/home/source/software/目录下。

mysql-5.1.30-linux-i686-glibc23

如果系统为64位,请下载mysql源码进行64位的编译安装。

shell> groupadd mysql
shell> useradd -g mysql mysql
shell> cd /usr/local
shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &
 cd support-files
 cp my-large.cnf /etc/my.cnf
 cp mysql.server /etc/rc.d/init.d/mysqld
 chkconfig --add mysqld
 chkconfig mysqld on
 service mysqld start
 /usr/local/mysql/bin/mysqld_safe   -user=mysql & //&以后台模式启动mysql
 设置mysql root密码
 /usr/local/mysql/bin/mysqladmin -u root password 密码 //全新安装的mysql没有密码
 修改mysql root密码
 /usr/local/mysql/bin/mysqladmin -u原密码 root password 新密码
 进入mysql
 /usr/local/mysql/bin/mysql -u root -p
 停止、启动mysql
 /usr/local/mysql/support-files/mysql.server { stat | stop }
 service mysqld { stat | stop }

MySQL路径为/usr/local/mysql

去PHP官网下载最新的源码包,我下的是php-5.2.6.tar.bz2。

pspell-.12.2.tar.gz

mkdir /usr/local/pspell
cd pspell-.12.2
./configure --prefix=/usr/local/pspell
make; make install

a.安装 jpeg6
建立目录:

mkdir -p /usr/local/jpeg
mkdir -p /usr/local/jpeg/bin
mkdir -p /usr/local/jpeg/lib
mkdir -p /usr/local/jpeg/include
mkdir -p /usr/local/jpeg/man
mkdir -p /usr/local/jpeg/man1
mkdir -p /usr/local/jpeg/man/man1
cd /home/source/software/
tar -zvxf jpegsrc.v6b.tar.gz
cd jpeg-6b
./configure --prefix=/usr/local/jpeg/ --enable-shared --enable-static
make; make install

备注:

在64 位下编译jpeg-6b时候报以下错误: 

make: ./libtool: Command not found 
make: *** [jcapimin.lo] Error 127 

错误分析:由于libtool版本过低导致的,重新下载新版本的libtool以默认方式安装,执行以下命令: 

./configure 
make 
make install 

然后进入jpeg-6b的源码目录,然后执行以下步骤,切记! 

cp /usr/share/libtool/config.sub . 
cp /usr/share/libtool/config.guess . 
./configure --prefix=/usr/local/jpeg/ --enable-shared --enable-static 
make 
make install 

 

b.:安装zlib

cd /home/source/software/
tar -zxvf zlib-1.2.3.tar.gz
mkdir -p /usr/local/zlib
cd zlib.1.2.3
./configure --prefix=/usr/local/zlib
make;make install

c.安装 freetype

cd /home/source/software/
tar -zvxf freetype-2.1.10.tar.gz
cd freetype-2.1.10
mkdir -p /usr/local/freetype
./configure --prefix=/usr/local/freetype
make;make install

d.安装libpng

cd /home/source/software/
mkdir -p /usr/local/png
tar -zvxf libpng-1.2.8.tar.gz
cd libpng-1.2.8
cp scripts/makefile.std makefile
 
vi makefile

不要用prefix定义路径否则会影响gd安装

ZLIBLIB=/usr/local/zlib
ZLIBINC=/usr/local/zlib/include
make; make install

e.安装gettext
ftp://ftp.gnu.org/gnu/gettext/gettext-0.17.tar.gz

tar xf gettext-0.17.tar.gz
cd gettext-0.17
mkdir /usr/local/gettext
./configure --prefix=/usr/local/gettext
make
make install

f.安装GD库

cd /home/source/software/
tar -zvxf gd-2.0.33.tar.gz
mkdir -p /usr/local/gd2
cd gd-2.0.33
./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg/
--with-zlib=/usr/local/zlib
--with-freetype=/usr/local/freetype/
--with-png
make; make install

安装GD
tar xzvf gd-2.0.35.tar.gz
cd gd-2.0.35
./configure –prefix=/usr/local/gd2 –with-jpeg=/usr/local/jpeg6/ –with-png –with-zlib –with-freetype=/usr/local/freetype/ –with-fontconfig=/usr/local/fontconfig
make
make install
错误:
configure.ac:64: error: possibly undefined macro: AM_ICONV
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
解决:
cd ..
tar zxvf gettext-0.17.tar.gz
cd gettext-0.17
./configure –prefix=/usr/local/gettext –disable-java –disable-native-java
make
make install
/bin/sed: can’t read /lib/libattr.la: No such file or directory
ln -s /usr/lib/* /lib/
再安装gettext
再安装gd

X86 64位LINUX下安装GD的注意事项
错误提示:
/usr/bin/ld: /usr/local/lib/libjpeg.a(jcapimin.o): relocation R_X86_64_32 against `a local symbol’ can not be used when making a shared object; recompile with -fPIC

进入Jpeg目录
CFLAGS=”-O3 -fPIC” ./configure
make
make install-lib

编译前需指定为64位编译模式,否则会出现以下错误:
/usr/bin/ld: /usr/local/lib/libz.a(crc32.o): relocation R_X86_64_32against `a local symbol’ can not be used when making a shared object;recompile with -fPIC
/usr/local/lib/libz.a: could not read symbols: Bad value
解决办法 : 重新安装 zlib-1.2.3.tar.gz

tar -zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure

vi Makefile
找到 CFLAGS=-O3 -DUSE_MMAP
在后面加入-fPIC,即变成CFLAGS=-O3 -DUSE_MMAP -fPIC
接下面步骤

make
make install

nfig.so -L/usr/lib64 /usr/local/freetype/lib/libfreetype.so -lpng -lz -lm -Wl,–rpath -Wl,/usr/local/freetype/lib -Wl,-soname -Wl,libgd.so.2 -o .libs/libgd.so.2.0.0
/usr/bin/ld: /usr/local/lib/libpng.a(png.o): relocation R_X86_64_32 against `a local symbol’ can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libpng.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
重新安装libpng;删除解压文件,重新解压
cp scripts/makefile.linux makefile
vi Makefile
找到 CFLAGS=后加上-fPIC
make test
make install

再重新安接gd;
vi Makefile
找到 CFLAGS=后加上-fPIC

g.安装Curl库

cd /home/source/software/
tar -zvxf curl-7.15.0.tar.gz
mkdir -p /usr/local/curl
./configure --prefix=/usr/local/curl
make; make install

h.安装libxml2

cd /home/xiutuo/software/
tar -zxvf libxml2-2.6.24.tar.gz
cd libxml2-2.6.24
mkdir -p /usr/local/libxml2
./configure --prefix=/usr/local/libxml2
make; make install

i.安装libiconv-1.12.tar.gz

tar -zxvf libiconv-1.12.tar.gz
cd libiconv-1.12
./configure --prefix=/usr/local/libiconv
make
make install
make clean

j.安装libmcrypt
ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz

tar xf libmcrypt-2.5.7.tar.gz
mkdir /usr/local/libmcrypt
cd libmcrypt-2.5.7
./configure --prefix=/usr/local/libmcrypt
make
make install

k.安装mhash

http://voxel.dl.sourceforge.net/sourceforge/mhash/mhash-0.9.9.tar.gz

tar xf mhash-0.9.9.tar.gz
cd mhash-0.9.9
mkdir /usr/local/mhash
./configure --prefix=/usr/local/mhash/
make;make install

j.安装PHP

如果使用PHP-FPM (PHP FastCGI Process Manager)来对进程进行管理,则需要提前做如下工作:
请阅读:《使用PHP-FPM (PHP FastCGI Process Manager)来对php-cgi进程进行管理》

$ sudo -s
$ mkdir /usr/local/php
$ mkdir /usr/local/php/sourcecode
$ mv ~/Download/php-5.2.6.tar.bz2 /usr/local/php/sourcecode
$ cd /usr/local/php/sourcecode
$ tar xf php-5.2.6.tar.bz2
$ cd php-5.2.6
$ ./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-fastcgi --enable-force-cgi-redirect --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-curl=/usr/local/curl --with-libxml-dir=/usr/local/libxml2 --with-libexpat-dir=/usr/lib --with-gd=/usr/local/gd2/ --with-jpeg-dir=/usr/local/jpeg/ --with-zlib-dir=/usr/local/zlib/ --with-png-dir=/usr/local/png/ --with-freetype-dir=/usr/local/freetype/ --enable-soap --enable-sockets --enable-dom --enable-sysvshm=yes --enable-ftp --enable-calendar --enable-sockets --with-db4 --with-bz2 --with-iconv=/usr/local/libiconv --with-gettext=/usr/local/gettext --with-mcrypt=/usr/local/libmcrypt --enable-mbstring=cn --with-mhash=/usr/local/mhash --with-mime-magic --with-openssl --disable-cli --enable-bcmath --enable-calendar --enable-ctype --enable-shmop --enable-soap --enable-sockets --enable-wddx --enable-zip --enable-dba=shared --enable-dbase --enable-exif --with-pspell=/usr/local/pspell --with-gmp
$ make
$ make install

当编译php时如果在64位系统下出现如下报错信息

checking for MySQL UNIX socket location… no
checking for mysql_close in -lmysqlclient… no
checking for mysql_error in -lmysqlclient… no
configure: error: mysql configure failed. Please check config.log for more information.
是使用了二进制的mysql所致,请下载mysql源码进行64位的编译安装。

说明:
sudo -s切换到超级用户模式,输入你的密码;
mkdir /usr/local/php建立php 5.2.6的安装目录;
mkdir /usr/local/php/sourcecode 并建立源码包存放位置,以方便日后快速的往php里面添加所须的模块;
解压缩,然后配置安装。

Mac OS 10.5不带PCRE,而PCRE又是NGINX不可缺少的,所以要我们自己安装。

$ mkdir -p /usr/local/src
$ cd /usr/local/src
$ curl -O ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.7.tar.gz
$ tar xvfz pcre-7.7.tar.gz
$ cd pcre-7.7
$ ./configure --prefix=/usr/local --enable-utf8
$ make
$ make install
$ cd ..

可以直接到官方下载源码包,也可以从用下面的CURL下载。

$ cd /tmp
$ curl -O http://sysoev.ru/nginx/nginx-0.6.32.tar.gz
$ tar xvfz nginx-0.6.32.tar.gz
$ cd nginx-0.6.32
$ ./configure --prefix=/usr/local/nginx --with-http_ssl_module
$ make
$ sudo make install

启动NGINX:

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

至此东西安装好了,看下http://localhost/,是不是nginx在欢迎你进入它的世界呢?呵呵,如果你看到了,那么恭喜你。

NGINX配置文件修改:

server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location ~ .*\.php?$ {
fastcgi_pass 127.0.0.1:1026;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

启动PHPCGI:

/usr/local/php/bin/php-cgi -q -b "127.0.0.1:1026"

此时你可以在/usr/local/nginx/html/底下写一个index.php,然后访问http://localhost/index.php
phpinfo();
?>

bash-3.2# curl -o http://www.lighttpd.net/download/lighttpd-1.4.20.tar.gz
bash-3.2# tar xf lighttpd-1.4.20.tar.gz
bash-3.2# cd lighttpd-1.4.20
bash-3.2# ./configure
bash-3.2# make
bash-3.2# cp src/spawn-fcgi /usr/local/nginx/sbin/

bash-3.2# /usr/local/nginx/sbin/spawn-fcgi -p 1026 -C 5 -u nobody -g nobody -f /usr/local/php/bin/php-cgi

也可以自己写个shell脚本,在此就不多写了。


大公告成~!

备注:

若出现这个错误

error while loading shared libraries: /usr/local/gd/lib/libgd.so.2: cannot restore segment prot after reloc: Permission denied

原来这是SELinux搞的鬼,解决办法有如下两个
1. 使用chcon 命令
示例: chcon -t texrel_shlib_t /usr/local/gd/lib/libgd/*.so.2
2. 禁止掉SELinux
更改/etc/sysconfig/selinux 文件的内容为 SELINUX=disabled

附加使用教程:
关闭NGINX:(Mac OS 用户可以通过活动监视器杀死nginx进程)

killall -9 nginx

不中断服务,重新启动NGINX:

ps -aux | grep nginx

查看主进程号pid

kill -HUP pid

作者:JoshuaLJD

nginx防盗链解决方案

方法一:

location ~* \.(js|css|jpg|png|gif|others)$ {
valid_referers none blocked *.sasacity.com sasacity.com;
if ($invalid_referer) {
rewrite ^/ http://www.sasacity.com/logo.gif;
#return 404;
}
}

方法二:
使用ngx_http_accesskey_module模块

配置例子:

location /download {
accesskey on;
accesskey_hashmethod md5;
accesskey_arg "key";
accesskey_signature "mypass$remote_addr";
}

此时客户端访问路径: http://example.com/download/file.zip?key=09093abeac094.

详细请见:http://wiki.codemongers.com/NginxHttpAccessKeyModule

Linux的下载命令wget

wget命令可以在linux下进行下载文件,这里的用法是摘自其GNU的帮助文档,由于都是E文,所以亲自用了一下,并记录其要点,以便日后翻阅:

Simple Usage 简单用法:
1、Say you want to download a URL. Just type:
wget http://fly.srk.fer.hr/ 最简单直接下载

2、But what will happen if the connection is slow, and the file is lengthy? The connection will probably fail before the whole file is retrieved, more than once. In this case, Wget will try getting the file until it either gets the whole of it, or exceeds the default number of retries (this being 20). It is easy to change the number of tries to 45, to insure that the whole file will arrive safely:
wget –tries=45 http://fly.srk.fer.hr/jpg/flyweb.jpg 注:–tries=45是当服务器无反应时,连续重试连接45次,当为0是则无限次重下载.

Now let’s leave Wget to work in the background, and write its progress to log file log. It is tiring to type –tries, so we shall use -t.
wget -t 45 -o log http://fly.srk.fer.hr/jpg/flyweb.jpg 注:-o log 把显示的信息写信到log文件中,亦可改为:wget -t 45 -o log.txt http://www.wcsky.com 即信息写入到log.txt文件中。

The ampersand at the end of the line makes sure that Wget works in the background. To unlimit the number of retries, use -t inf.

The usage of FTP is as simple. Wget will take care of login and password.
wget ftp://gnjilux.srk.fer.hr/welcome.msg

Advanced Usage 高级用法
1、Create a five levels deep mirror image of the GNU web site, with the same directory structure the original has, with only one try per document, saving the log of the activities to gnulog:
wget -r http://www.gnu.org/ -o log 注:-r 下载http://www.gnu.org/文件的镜像内容。

The same as the above, but convert the links in the HTML files to point to local files, so you can view the documents off-line:
wget –convert-links -r http://www.gnu.org/ -o gnulog 注:下载http://www.gnu.org/文件的镜像内容以及内容中的链接为本地的链接。

2、Retrieve only one HTML page, but make sure that all the elements needed for the page to be displayed, such as inline images and external style sheets, are also downloaded. Also make sure the downloaded page references the downloaded links.
wget -p –convert-links http://www.server.com/dir/page.html

The HTML page will be saved to www.server.com/dir/page.html, and the images, stylesheets, etc., somewhere under www.server.com/, depending on where they were on the remote server.

3、The same as the above, but without the www.server.com/ directory. In fact, I don’t want to have all those random server directories anyway–just save all those files under a download/ subdirectory of the current directory.
wget -p –convert-links -nH -nd -Pdownload http://www.server.com/dir/page.html

wget -Pdownload http://www.wcsky.com 注:下载http://www.wcsky.com里的面容到download文件夹中,如果此文件夹不存在,它会自动创建。

4、Retrieve the index.html of www.lycos.com, showing the original server headers:
wget -S http://www.lycos.com/ 注:-S : 用来显示服务器端的头信息,

5、Save the server headers with the file, perhaps for post-processing.
wget -s http://www.lycos.com/ 注:-s:下载其URL文件,并把头信息写入到文件中。

6、Retrieve the first two levels of wuarchive.wustl.edu, saving them to /tmp.
wget -r -l2 -P/tmp ftp://wuarchive.wustl.edu/

7、You want to download all the GIFs from a directory on an HTTP server. You tried wget http://www.server.com/dir/*.gif, but that didn’t work because HTTP retrieval does not support globbing. In that case, use:
wget -r -l1 –no-parent -A.gif http://www.server.com/dir/

More verbose, but the effect is the same. -r -l1 means to retrieve recursively (see Recursive Retrieval), with maximum depth of 1. –no-parent means that references to the parent directory are ignored (see Directory-Based Limits), and -A.gif means to download only the GIF files. -A “*.gif” would have worked too.

8、Suppose you were in the middle of downloading, when Wget was interrupted. Now you do not want to clobber the files already present. It would be:
wget -nc -r http://www.gnu.org/

wget -c http://www.wcsky.com/1.mp3 注:-c:用于断点续传。超实用!!

9、If you want to encode your own username and password to HTTP or FTP, use the appropriate URL syntax (see URL Format).
wget ftp://hniksic:mypassword@unix.server.com/.emacs

Note, however, that this usage is not advisable on multi-user systems because it reveals your password to anyone who looks at the output of ps.

10、You would like the output documents to go to standard output instead of to files?
wget -O – http://jagor.srce.hr/ http://www.srce.hr/

You can also combine the two options and make pipelines to retrieve the documents from remote hotlists:wget -O – http://cool.list.com/ | wget –force-html -i -

Apache和Subversion集成安装与配置

因为工作需要,要架设一个Subversion和Apache一起工作的源码管理器.以便协同工作.于是网上找了一些资料,在找资料的过程中,也走了一些弯路,于是自己整理了一下安装的过程和一些注意的事项,希望能对大家有些帮助.
我这里用的IDE是netbeans6.0,其实用什么IDE都无所谓,只是netbeans一直是我喜欢的IDE,所以顺便向大家推荐一下.呵呵.
好了,言归正传吧,要准备的东西如下:
1,apache_2.0.63-win32-x86-no_ssl.msi
下载:http://apache.mirror.phpchina.com/httpd/binaries/win32/apache_2.0.63-win32-x86-no_ssl.msi
2,svn-1.4.5-setup.exe
下载地址:http://subversion.tigris.org/files/documents/15/39559/svn-1.4.5-setup.exe
当然,你也可以选择安装TortoiseSVN.但是我没有装,因为我的源码管理都是用netbeans完成的.

好了,准备的两个软件都下载下来以后,就可以开始安装了.
首先安装apache,一般来说直接点下一步就可以了,在设置domain以及host的时候,设置为localhost就可以了,Email你可以填你 自己的Email,也可以随便填一个.安装apache要注意的是,你的电脑上80端口不能被占用,否则你的http服务是启动不起来的,我就遇到过这 事,因为我用了skype,它在本机上打开了80和443端口来监听,搞得我一开始装不好,总是启动不起来,后来才发现是skype占用了80端口,于是 把skype的设置改了以后,重装apache才成功.装好apache以后,这个时候,它已经在运行了,你可以在浏览器的地址栏输入 http://localhost看看,是否安装成功,如果安装成功的话,这个时候浏览器里面应该是可以看到一个页面的.
然后,再安装svn-1.4.5-setup.exe,也很简单,一步一步点下步就可以了,在安装的过程中,它会默认选中一些选项,其中就有一个是是否对 apache的HTTP服务器提供支持的选项,这个默认是勾上的,不要去反选它,其它的你可以反选掉.然后svn就宣布安装成功了.你可以到CMD下面去 试一下svn这个命令,如果有输出,则说明安装成功了,如果提示svn 不是内部或外部命令,也不是可运行的程序或批处理文件。那就说明没有装好.或者没有把这个命令加入到path中,所以最好的办法是到svn的安装目录下的 bin里面去看一下.
两者都装好了以后,就开始配置,当然,配置也是最重要的.
首先要建立一个数据仓库,我们假设建在E盘,数据仓库最好不要建在C盘,因为C盘重装系统以后就格了.我们先在E盘下面建立一个目录叫svnroot,然 后在svnroot下面再建立一个我们专门放我们工程的目录,比如叫MyProject.于是我们在E盘下面就有了这个一个文件夹:E:\svnroot\MyProject,然后我们用svnadmin的命令,使这个文件夹变成我们的数据仓库,命令如下:
svnadmin create E:\svnroot\MyProject
如果运行成功的话,什么也没有输出,这个时候,我们再来到MyProject文件夹下面,我们会发现多了几个文件夹和文件,我们打开conf文件夹,然后再打开svnserve.conf文 件,找到如下行# password-db = passwd,然后把它前面的#去掉,表示MyProject是需要密码验证的.但是我们密码设在哪里呢,这个时候我们再打开conf文件夹下面的 passwd文件,用文本编辑器打开,在[users]下面加上我们需要启动的人员的用户和密码,比如
[users]
hadeslee=hadeslee1234
tom=123456

这个的话,我们就启动了两个用户,一个叫hadeslee,密码是hadeslee1234,一个叫tom,密码是123456.然后我们保存passwd文件.然后,我们再建一个文件,叫access.auth,这个文件是设置访问权限的,里面内容如下:
[MyProject:/]
hadeslee = rw
[MyProject:/module1]
tom=rw
hadeslee=rw

这表示,MyProject下面的所有子目录hadeslee都是有权限读写的,但是tom只有权限读写此项目下面的module1目录,这个各自的访问 权限就分的更细致了.有关于MyProject文件夹下面的设置,我们就告一段落了,我们现在开始设置apache,使它能和subvertion一起工 作.

首先来到Subersion的安装目录,进入它的bin目录,我们会发现如下两个文件:
mod_authz_svn.so
mod_dav_svn.so

我们把这两个文件复制一下,粘帖到apache的安装目录下的modules文件中,然后我们再打开apache安装目录下的conf文件夹,打开httpd.conf文件.增加如下两行:
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so

注意,由于dav_svn需要dav_module的支持,所以要确保下面这一行没有被注释,并且保证在dav_svn之前加载:
LoadModule dav_module modules/mod_dav.so
然后模块的设置就完成了,下面我们要设置SVN的目录,以使我们的apache能知道访问不同的URL的时候,它去哪里寻找这个URL所对应的SVN目录.
httpd.conf文件中,增加如下内容:
<Location /svn/MyProject>
DAV svn
SVNPath E:/svnroot/MyProject

AuthzSVNAccessFile E:/svnroot/MyProject/conf/access.auth
Satisfy Any
Require valid-user

AuthType Basic
AuthName “Subversion repositories”
AuthUserFile  E:/svnroot/MyProject/conf/users.auth
Require valid-user
</Location>

添加完上面这些,我们会发现access.auth是我们刚才新建的,可是users.auth我们并没有新建啊.怎么就把它加进去了.不要急,现在我们就来生成users.auth文件.

进入apache的安装目录的bin文件夹,输入如下命令:

D:\Program Files\Apache Group\Apache2\bin>htpasswd -cb users.auth hadeslee hadeslee1234
Automatically using MD5 format.
Adding password for user hadeslee

D:\Program Files\Apache Group\Apache2\bin>

我们就会发现在bin目录生成了users.auth,我们可以看到,hadeslee用户名已经被添加进去了,密码是用MD5加密过的.然后我们还要增加用户呢,可以用如下方法:
D:\Program Files\Apache Group\Apache2\bin>htpasswd -b users.auth tom 123456
Automatically using MD5 format.
Adding password for user tom

D:\Program Files\Apache Group\Apache2\bin>

只是在生成密码的时候,小了一个c的参数,因为c表示重新生成一个这样的文件,我们第一次的时候是要加的,后面我们要添加用户的时候,就不用这个c了.然后打开users.auth,会发现两个用户都已经在里面了,这个时候,我们把users.auth移到E:/svnroot/MyProject/conf/里面去,使我们上面的设置生效.

这个时候,我们的设置就完成了.可以在浏览器里面输入http://localhost/svn/MyProject试试看.

如果以后我们还要加入其它的项目呢,可以有两点解决方式
1,把以后的项目也导入到我们的MyProject的仓库中,这个的话,就不用改什么配置了
2,新建一个数据仓库,然后只要按上面的步骤,把新的<Location…>设置放到httpd.conf里面就可以了.
当然,验证文件,访问权限文件,还有访问SVN的密码都要自己按上面的方法再设一遍.

祝大家能够设置成功:)

Nginx重定向[Rewrite]配置及示例 (for zendframework & wordpress & Discuz)

首先Apache的Rewite规则差别不是很大,但是Nginx的Rewrite规则比Apache的简单灵活多了
Nginx可以用if进行条件匹配,语法规则类似C

if ($http_user_agent ~ MSIE) {
rewrite ^(.*)$ /msie/$1 break;
}

官方文档请点击这里
Rewrite的Flags

Flags can be any of the following:
* last - completes processing of rewrite directives, after which searches for corresponding URI and location
* break - completes processing of rewrite directives
*redirect - returns temporary redirect with code 302; it is used if the substituting line begins with http://
* permanent - returns permanent redirect with code 301

last – 完成重写指令后,搜索相应的URI和位置。相当于Apache里的[L]标记,表示完成rewrite,不再匹配后面的规则。
break – 中止Rewirte,不在继续匹配。
redirect – 返回临时重定向的HTTP状态302。
permanent – 返回永久重定向的HTTP状态301。

ZEND Framework的重定向规则:
案例一:
全部重定向到 /index.php
rewrite ^/(.*) /index.php?$1&amp;;
案例二:
如果文件或目录不存在则重定向到index.php
if (!-e $request_filename) {
rewrite ^/(.*) /index.php?$1&amp;;
}

WordPress的重定向规则:
案例一:
http://www.wemvc.com/12 重定向到 http://www.wemvc.com/index.php?p=12
if (!-e $request_filename) {
rewrite ^/(.+)$ /index.php?p=$1 last;
}

案例二:
与zendframework配置很像
if (!-e $request_filename) {
rewrite ^/(.*) /index.php?$1&amp;;
}

以下为Discuz完整的Rewrite for Nginx规则
if (!-f $request_filename) {
rewrite ^/archiver/((fid|tid)-[\w\-]+\.html)$ /archiver/index.php?$1 last;
rewrite ^/forum-([0-9]+)-([0-9]+)\.html$ /forumdisplay.php?fid=$1&amp;page=$2 last;
rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /viewthread.php?tid=$1&amp;extra=page%3D$3&amp;page=$2 last;
rewrite ^/space-(username|uid)-(.+)\.html$ /space.php?$1=$2 last;rewrite ^/tag-(.+)\.html$ /tag.php?name=$1 last;
}

文件及目录匹配,其中:
-f和!-f用来判断是否存在文件
-d和!-d用来判断是否存在目录
-e和!-e用来判断是否存在文件或目录
-x和!-x用来判断文件是否可执行

正则表达式全部符号解释
~ 为区分大小写匹配
~* 为不区分大小写匹配
!~和!~* 分别为区分大小写不匹配及不区分大小写不匹配
(pattern) 匹配 pattern 并获取这一匹配。所获取的匹配可以从产生的 Matches 集合得到,在VBScript 中使用 SubMatches 集合,在JScript 中则使用 $0…$9 属性。要匹配圆括号字符,请使用 ‘\(‘ 或 ‘\)’。
^ 匹配输入字符串的开始位置。
$ 匹配输入字符串的结束位置。
学习更多正则知识请查看这里 正则表达式

Restriction of the access with the help of Nginx

In this short post the point is how to protect your files and some part of your web site with a user password. With Nginx, a lot of options exist to protect your site with usernames and passwords. In Nginx the solution is not less attractive than in apache.

In the configuration file, set folder to close, it is only necessary to load the file with passwords.
There are two examples for closing of the folder with files:
location ^~ /files/ {
root   /path/to/server;
autoindex    on;
autoindex_exact_size  off;
auth_basic “Hello, please login”;
auth_basic_user_file /usr/nginx/passwords;
access_log   /usr/nginx/logs/files.log   download;
}
and for closing of the admin-folder with the additional restriction on IP:
location ^~ /admin/ {
fastcgi_pass unix:/home/project/server.sock;
include  conf/fastcgi.conf;
allow 11.11.0.0/16;
allow 22.22.22.22;
deny all;
auth_basic “Hello, Admin, please login”;
auth_basic_user_file /usr/nginx/adminpassword;
access_log   /usr/nginx/logs/admin.log  main;
}
The passwd program utility of Apache can be used to create and update usernames and passwords of new users:
htpasswd -b passwords NewUser NewPassword
In the file the writing with the encoded password looks like:
NewUser:P47ghZ4kloG78: Your Can Comment Here
The protection from cracking the password can be organized at the same time with two methods based on the use iptables:
Blocking IP temporarily if the amount of the requests per second exceeds any reasonable amount.
Write failed attempts in the log, check it with the script every minute, than pumps the IP addresses in iptables
For the first variant it is enough to create rules:
iptables -A INPUT -p tcp –syn –dport 80 -i eth0 -m state –state NEW
-m recent –name bhttp –set
iptables -A INPUT -p tcp –syn –dport 80 -i eth0 -m state –state NEW
-m recent –name bhttp –update –seconds 120
–hitcount 360 -j DROP
iptables -A INPUT -p tcp –syn –dport 80 -i eth0 -j ACCEPT
It is possible to use TARPIT instead of DROP to complicate the life of the crackers.

For the second variant it is necessary to add in config:
location /401.html {
root   /usr/nginx;
access_log   /usr/nginx/logs/denied.log  error401;
}
For example the format error 401 looks at me:
log_format error401  ‘$remote_addr – $remote_user [$time_local] ‘
‘$status “$request”‘;
Now all wrong logins are saved in a separate log file, which is checked per cron job:
*/1 * * * * root /usr/nginx/parser401.pl >/dev/null 2>&1
For example this script: parser401.pl Скрипт проверяет лог, и если обнаруживает больше 4-х попыток неправильного набора пароля, блокирует этот IP. Script checks the log file and if it finds more than 4 attempts of the wrong password, it blocks this IP address.
Are there any ideas?