Setup on Linode.com with ubuntu+nginx+php+fastcgi+mysql 续

嗯嗯,继续。

  • nginx和fastcgi启动配置

    2个配置文件,放于/etc/init.d下面。

    cd /etc/init.d
    touch fast-cgi
    touch nginx
    sudo chmod +x /etc/init.d/nginx /etc/init.d/fast-cgi

    nginx

    #! /bin/sh
    
    ### BEGIN INIT INFO
    # Provides:          nginx
    # Required-Start:    $all
    # Required-Stop:     $all
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: starts the nginx web server
    # Description:       starts nginx using start-stop-daemon
    ### END INIT INFO
    
    PATH=/usr/local/nginx/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    DAEMON=/usr/local/nginx/sbin/nginx
    NAME=nginx
    DESC=nginx
    
    test -x $DAEMON || exit 0
    
    # Include nginx defaults if available
    if [ -f /etc/default/nginx ] ; then
    	. /etc/default/nginx
    fi
    
    set -e
    
    . /lib/lsb/init-functions
    
    test_nginx_config() {
      if nginx -t
      then
        return 0
      else
        return $?
      fi
    }
    
    case "$1" in
      start)
    	echo -n "Starting $DESC: "
            test_nginx_config
    	start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
    		--exec $DAEMON -- $DAEMON_OPTS || true
    	echo "$NAME."
    	;;
      stop)
    	echo -n "Stopping $DESC: "
    	start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
    		--exec $DAEMON || true
    	echo "$NAME."
    	;;
      restart|force-reload)
    	echo -n "Restarting $DESC: "
    	start-stop-daemon --stop --quiet --pidfile \
    		/var/run/$NAME.pid --exec $DAEMON || true
    	sleep 1
            test_nginx_config
    	start-stop-daemon --start --quiet --pidfile \
    		/var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
    	echo "$NAME."
    	;;
      reload)
            echo -n "Reloading $DESC configuration: "
            test_nginx_config
            start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/$NAME.pid \
                --exec $DAEMON || true
            echo "$NAME."
            ;;
      configtest)
            echo -n "Testing $DESC configuration: "
            if test_nginx_config
            then
              echo "$NAME."
            else
              exit $?
            fi
            ;;
      status)
    	status_of_proc -p /var/run/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
    	;;
      *)
    	echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest}" >&2
    	exit 1
    	;;
    esac
    
    exit 0

    fast-cgi

    #! /bin/sh
    
    ### BEGIN INIT INFO
    # Provides:          fast-cgi
    # Required-Start:    $all
    # Required-Stop:     $all
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: starts the fast-cgi web server
    # Description:       starts fastcgi using start-stop-daemon
    ### END INIT INFO
    
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    
    NAME=spawn-fcgi
    DESC=spawn-fcgi
    DAEMON=/usr/local/bin/spawn-fcgi
    
    DAEMON_OPTS="-u www-data -g www-data -C 8 -a 127.0.0.1 -p 9000 -P /var/run/$NAME.pid -- /usr/bin/php5-cgi"
    
    test -x $DAEMON || exit 0
    
    set -e
    
    case "$1" in
      start)
    	echo -n "Starting $DESC: "
    	start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
    	echo "$NAME."
    	;;
      stop)
    	echo -n "Stopping $DESC: "
    	start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid --exec $DAEMON || true
    	echo "$NAME."
    	;;
      restart|force-reload)
    	echo -n "Restarting $DESC: "
    	start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid --exec $DAEMON || true
    	sleep 1
    	start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
    	echo "$NAME."
    	;;
      reload)
          echo -n "Reloading $DESC configuration: "
          start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/$NAME.pid --exec $DAEMON || true
          echo "$NAME."
          ;;
      *)
    	N=/etc/init.d/$NAME
    	echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
    	exit 1
    	;;
    esac
    exit 0

    这两个脚本需要注意的是目录的定位,如果在编译阶段加入了目录设置的参数,那么你同时需要在这里修改定义。另外fast-cgi需要注意DAEMON_OPTS的参数设置。

    这2个脚本都有一个同样的问题,就是无法正常停止服务。我虽然不太了解shell程序,但是根据我其他编程经验,两个脚本都是通过start-stop-daemon命令来开启和停止服务。但我使用的情况是可以正常开启,但无法正常关闭。所以我不得不写了一个简单的关闭并重启nginx服务的脚本,是通过直接kill进程来实现的。

    cd ~
    mkdir tools
    cd tools
    touch reset_nginx
    chmod +x reset_nginx

    reset_nginx内容

    sudo kill `cat /usr/local/nginx/logs/nginx.pid`
    sudo /etc/init.d/nginx start

    但是fast-cgi的服务即使我kill进程并删除pid文件也无济于事,fast-cgi仍然照常运行……这有点不合逻辑,也许我操作错误,或者是权限问题。不过fast-cgi开启后一般也没有必要进行重启或其他操作,这个问题留待以后解决吧。或者有哪位同学知道的,请不吝赐教!

    最后这2个脚本需要注册为系统服务,需要安装rcconf。

    sudo apt-get install rcconf
    sudo rcconf

    嗯,很怀旧的DOS操作界面……呵呵,大家选择2个脚本,再ok退出即可。

  • nginx站点配置

    由于dreamhost的习惯,并且这个虚拟机还要放callaly的blog(http://callaly.net),所以nginx的站点我放到用户目录下去了。

    cd ~
    mkdir wwwroot
    cd wwwroot
    mkdir yourdomain.com

    编辑/usr/local/nginx/conf/nginx.conf

    user www-data;
    worker_processes 2;
    
    events {
    	worker_connections  1024;
    	use epoll;
    }
    
    http {
    	include       mime.types;
    	default_type  application/octet-stream;
    
    	sendfile       on;
    	tcp_nopush     on;
    	tcp_nodelay    on;
    
    	keepalive_timeout  65;
    
    	gzip  on;
    
    	#设置默认站点,禁止所有IP访问
    	server {
    		listen 80 default;
    		return 403;
    	}
    
    	#包含其他站点配置
    	include /usr/local/nginx/sites-enabled/*;
    
    }

    创建站点文件

    cd /usr/local/nginx
    sudo mkdir sites-available
    sudo mkdir sites-enabled
    sudo touch sites-available/yourdomain.com
    sudo ln -s sites-available/yourdomain.com sites-enabled/yourdomain.com
    	

    编辑sites-available/yourdomain.com

    server {
    	listen       80;
    	server_name  www.yourdomain.com yourdomain.com;
    
    	access_log	/home/myname/wwwroot/log/yourdomain.com.access.log;
       	error_log	/home/myname/wwwroot/log/yourdomain.com.error.log;
    
    	location / {
    		root   /home/myname/wwwroot/yourdomain.com;
    		index  index.html index.htm index.php;
    
    		# WordPress URL优化
    		if (-f $request_filename) {
    			break;
    		}
    		if (-d $request_filename) {
    			break;
    		}
    
    		# WordPress URL重写,如果你的wp目录不在根目录,请修改路径
    		rewrite ^(.+)$ /index.php?q=$1 last;
    	}
    
    	location ~ \.php$ {
    		fastcgi_pass	127.0.0.1:9000;
    		fastcgi_index	index.php;
    		fastcgi_param	SCRIPT_FILENAME /home/myname/wwwroot/yourdomain.com$fastcgi_script_name;
    		include		/usr/local/nginx/conf/fastcgi_params;
    	}
    
    	#如果前面编译nginx时添加了with-http_stub_status_module参数
    	#就可以通过此设置访问yourdomain.com/status(名称自定)查看站点状态
    	location /status {
    		stub_status on;
    		access_log off;
    	}
    }

    nginx的站点配置基本ok

  • wordpress备份和恢复

    需要把dreamhost主机上的内容迁移过来,可操作方法很多,最好在服务器端直接操作,速度更快。文件操作很简单不赘述,关于数据库的备份和恢复简单说下。

    #导出 - 在原服务器
    mysqldump -h old_host -p old_dbname -u old_dbuser >wp_bak.sql
    
    #登录mysql
    mysql -h new_host -u new_dbuser
    
    #创建新数据库,注意编码
    create database 'new_dbname' default character set utf8 collate utf8_general_ci;
    
    #导入 - 确保备份sql文件在当前目录
    use new_dbname;
    source wp_bak.sql;

    至此整个站点配置已经基本完成,可以敲域名访问了。

这篇文章大部分内容来自于网上,我东拼西凑来的,特在此列出供大家参考。

ubuntu flash中文乱码

sudo gedit /etc/fonts/conf.d/49-sansserif.conf

替换sans-serif或者serif为wqy-zenhei(或其他你喜欢的中文字体)即可。

ubuntu 9.04 with vbox2.2.2

感觉ubuntu运行在vbox下和独立运行区别不大,都比较流畅。开启3D以后屏幕刷新有点问题,估计内存设的小点的缘故,关了一切就ok。可以尝试作为开发环境,在windows下开发linux环境程序太痛苦了。

ubuntu 9.04的桌面可用性又好了很多,最直接一点,安装后默认的字体已经很漂亮了,不用再调整字体了……

一个好源(杭州电信ADSL连接)

deb http://ftp.sjtu.edu.cn/ubuntu/ jaunty main multiverse restricted universe
deb http://ftp.sjtu.edu.cn/ubuntu/ jaunty-backports main multiverse restricted universe
deb http://ftp.sjtu.edu.cn/ubuntu/ jaunty-proposed main multiverse restricted universe
deb http://ftp.sjtu.edu.cn/ubuntu/ jaunty-security main multiverse restricted universe
deb http://ftp.sjtu.edu.cn/ubuntu/ jaunty-updates main multiverse restricted universe
deb-src http://ftp.sjtu.edu.cn/ubuntu/ jaunty main multiverse restricted universe
deb-src http://ftp.sjtu.edu.cn/ubuntu/ jaunty-backports main multiverse restricted universe
deb-src http://ftp.sjtu.edu.cn/ubuntu/ jaunty-proposed main multiverse restricted universe
deb-src http://ftp.sjtu.edu.cn/ubuntu/ jaunty-security main multiverse restricted universe
deb-src http://ftp.sjtu.edu.cn/ubuntu/ jaunty-updates main multiverse restricted universe

Go With Ubuntu 6.10

捣鼓了几天linux,终于基本搞定了。字体美化,源更新,自动更新,多媒体支持,聊天工具,BT……开始用吧 Linux

Go With Ubuntu 6.10