2009/01
7
我的本博客由
Dreamhost提供空间. 但部分教育网同学无法访问到或速度极慢.于是产生了一个使用Nginx建立代理服务器
cn.luochunhui.com的想法
设置原理:
用户访问cn.luochunhui.com(上海S1) => S1访问www.luochunhui.com(美国S2) => S2返回内容给S1 => S1返回内容给用户.
设置方法:
增加Nginx配置文件:
#file: /etc/nginx/sites-enabled/cn.luochunhui.com
server {
listen 80;
server_name cn.luochunhui.com;
access_log /var/www/logs/cn.luochunhui.com_access.log;
location /robots.txt {
root /home/rollenc/luochunhui.com;
}
location / {
proxy_pass http://www.luochunhui.com;
}
}
其中有一段 关于 robots.txt 的设置. 是关于SEO方面的. 在代理服务器上设置了一个 robots文件, 告诉蜘蛛别爬cn域.
Defined tags for this entry:
nginx
Posted by rollenc
Last modified on 2009-01-07 23:04
2009/01
7
今天搞定了一台Nginx服务器,替代了lighttpd。 记录一下安装
系统: Ubuntu 8.04 Server amd64
1. 安装Nginx及php cgi
sudo apt-get install build-essential nginx php5-common php5-cgi
2. 启用php fastcgi
/etc/nginx/sites-available/default
ref: defaultPHP
==================================
server {
listen 80;
client_max_body_size 50M;
server_name localhost;
root /var/www/nginx-default;
access_log /var/log/nginx/localhost.access.log;
location / {
index index.html index.php;
expires max;
break;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;
include /etc/nginx/fastcgi.conf;
expires max;
}
error_page 500 502 503 504 /50x.html;
location = /500.html { root /var/www/nginx-default; }
}
3. 设置fastcgi参数
/etc/nginx/fastcgi.conf
ref: fastcgi.conf
=========================
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
4. 建立fastcgi 脚本
/etc/init.d/php-fastcgi
ref: php-fastcgi
=======================
#!/bin/sh
### BEGIN INIT INFO
# Provides: php-fastcgi
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start and stop php-cgi in external FASTCGI mode
# Description: Start and stop php-cgi in external FASTCGI mode
### END INIT INFO
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="php-cgi in external FASTCGI mode"
NAME=php-fastcgi
DAEMON=/usr/bin/php-cgi
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
[ -x "$DAEMON" ] || exit 0
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
. /lib/lsb/init-functions
if [ "$START" != "yes" -a "$1" != "stop" ]; then
log_warning_msg "To enable $NAME, edit /etc/default/$NAME and set START=yes"
exit 0
fi
export PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS
DAEMON_ARGS="-q -b $FCGI_HOST:$FCGI_PORT"
do_start()
{
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null || return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --background --make-pidfile --chuid $EXEC_AS_USER --startas $DAEMON -- $DAEMON_ARGS || return 2
}
do_stop()
{
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE > /dev/null # --name $DAEMON
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
rm -f $PIDFILE
return "$RETVAL"
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
:
How to setup an Ubuntu 7.10 server with nginx, php, mysql, ruby, radiant, mongrel (mongrel_cluster), monit and a simple firewall.
Defined tags for this entry:
nginx
Posted by rollenc
Last modified on 2009-01-07 22:28