1.安装centos6.5  32位系统

2.配置网卡

#dhclient    //自动获取IP

#ifconfig -a //查看网卡信息

#vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
HWADDR=00:0C:29:A0:C8:44
TYPE=Ethernet
UUID=3e33bb90-a14f-4911-8ecf-7df6ed5d296c
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.0.66
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
DNS=8.8.8.8   //输入自已的DNS

#service network start //启动网卡

3.配置远程工具PuTTy

4系统更新,安装需要的软件

yum update -y //更新系统
yum groupinstall -y "Development Tools"  //开发工具
yum install -y vim wget //安装vim和wget软件

5.编译安装Nginx

[root@localhost ~]# cd /usr/local/src

[root@localhost src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz

[root@localhost src]# tar -zxvf nginx-1.6.2.tar.gz

[root@localhost src]# cd nginx-1.6.2
[root@localhost nginx-1.6.2]#

./configure \
--prefix=/usr/local/nginx \
--with-http_realip_module \
--with-http_sub_module \
--with-http_gzip_static_module \
--with-http_stub_status_module  \
--with-pcre

以上编译执行时会出现错误如下

1.“checking for PCRE library … not found checking for PCRE library in /usr/local/ … not found checking for PCRE library in /usr/include/pcre/ … not found checking for PCRE library in /usr/pkg/ … not found checking for PCRE library in /opt/local/ … not found ./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using –without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using –with-pcre=<path> option.”

请安装:yum install pcre-devel

2.“./configure: error: the HTTP gzip module requires the zlib library. You can either disable the module by using –without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using –with-zlib=<path> option.”

请安装:yum install zlib zlib-devel


注意说明:处理完错误后,应重新执行一次 ./configure     ......... 直到没有错误。才能#make和#make install


[root@localhost nginx-1.6.2]# /usr/local/nginx/sbin/nginx  //启动nginx


[root@localhost nginx-1.6.2]# iptables -F  清空防火墙


[root@localhost nginx-1.6.2]# ps aux |grep nginx  //nginx是否启动


[root@localhost nginx-1.6.2]# netstat -lnp //nginx端口是否启动


在IE是输入http://192.168.0.66/   可以看到  Welcome to nginx!    表示nginx安装成功!!!!



6.安装Node.js


Run as root on RHEL, CentOS or Fedora:

curl --silent --location https://rpm.nodesource.com/setup | bash -


Then install, as root:

yum -y install nodejs

node -v  npm -v  #检查是否安装成功


7.安装ghost

#  mkdir -p /ghost/www

# cd /ghost/www

#  wget http://dl.ghostchina.com/Ghost-0.7.0-zh-full.zip  //ghost中文安装集成包


#  unzip -uo Ghost-0.7.0-zh-full.zip  //解压


#  npm install --production  //安装


#  npm start //启动


#  npm install forever -g   //安装forever ,后台运行启动npm


#   forever start index.js  //启动


说明:

#  vi config.js

找到development,url地址修改一下

下面的server127.0.0.1改为0.0.0.0


# server: {                       //第37行
            host: '192.168.0.66',// 输入服务器的IP
            port: '2368'
        },


IE上输入192.168.0.66:2368  就可以看到ghost主页。



8.nginx 启动脚本

vim /etc/init.d/nginx

#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings

NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"

start() {
        echo -n $"Starting $prog: "
        mkdir -p /dev/shm/nginx_temp
        daemon $NGINX_SBIN -c $NGINX_CONF
        RETVAL=$?
        echo
        return $RETVAL
}

stop() {
        echo -n $"Stopping $prog: "
        killproc -p $NGINX_PID $NGINX_SBIN -TERM
        rm -rf /dev/shm/nginx_temp
        RETVAL=$?
        echo
        return $RETVAL
}

reload(){
        echo -n $"Reloading $prog: "
        killproc -p $NGINX_PID $NGINX_SBIN -HUP
        RETVAL=$?
        echo
        return $RETVAL
}

restart(){
        stop
        start
}

configtest(){
    $NGINX_SBIN -c $NGINX_CONF -t
    return 0
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload)
        reload
        ;;
  restart)
        restart
        ;;
  configtest)
        configtest
        ;;
  *)
        echo $"Usage: $0 {start|stop|reload|restart|configtest}"
        RETVAL=1
esac

exit $RETVAL


保存后,更改权限:

chmod 755 /etc/init.d/nginx
chkconfig --add nginx

如果想开机启动,请执行:

chkconfig nginx on


9.更改nginx配置文件


#  > /usr/local/nginx/conf/nginx.conf  //清空

vim /usr/local/nginx/conf/nginx.conf

写入如下内容:

user nobody nobody;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;

events
{
    use epoll;
    worker_connections 6000;
}

http
{
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 3526;
    server_names_hash_max_size 4096;
    log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
    '$host "$request_uri" $status'
    '"$http_referer" "$http_user_agent"';
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 30;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    connection_pool_size 256;
    client_header_buffer_size 1k;
    large_client_header_buffers 8 4k;
    request_pool_size 4k;
    output_buffers 4 32k;
    postpone_output 1460;
    client_max_body_size 10m;
    client_body_buffer_size 256k;
    client_body_temp_path /usr/local/nginx/client_body_temp;
    proxy_temp_path /usr/local/nginx/proxy_temp;
    fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
    fastcgi_intercept_errors on;
    tcp_nodelay on;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;
    gzip_comp_level 5;
    gzip_http_version 1.1;
    gzip_types text/plain application/x-javascript text/css text/htm application/xml;

server
{
    listen 80;
    server_name localhost;
    index index.html index.htm index.php;
    root /usr/local/nginx/html;

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/tmp/php-fcgi.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
    }

}

}



# /usr/local/nginx/sbin/nginx  -t  //检查配置是否有错误。



service nginx start


ps aux |grep nginx



10.nginx 反代理


#  mkdir /usr/local/nginx/conf/vhosts //创建虚拟主机

#  vim /usr/local/nginx/conf/nginx.conf

user nobody nobody;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;

events
{
    use epoll;
    worker_connections 6000;
}

http
{
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 3526;
    server_names_hash_max_size 4096;
    log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
    '$host "$request_uri" $status'
    '"$http_referer" "$http_user_agent"';
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 30;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    connection_pool_size 256;
    client_header_buffer_size 1k;
    large_client_header_buffers 8 4k;
    request_pool_size 4k;
    output_buffers 4 32k;
    postpone_output 1460;
    client_max_body_size 10m;
    client_body_buffer_size 256k;
    client_body_temp_path /usr/local/nginx/client_body_temp;
    proxy_temp_path /usr/local/nginx/proxy_temp;
    fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
    fastcgi_intercept_errors on;
    tcp_nodelay on;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;
    gzip_comp_level 5;
    gzip_http_version 1.1;
    gzip_types text/plain application/x-javascript text/css text/htm application/xml;

   
    include vhosts/*.conf;

}

#  /usr/local/nginx/sbin/nginx -t

#  service  nginx reload

#  vim /usr/local/nginx/conf/vhosts/ghost.conf


server  {
    listen          80;
    server_name     blog.tonytu.com;
    location / {
        proxy_pass              http://192.168.0.66:2368/;
        proxy_set_header        Host   $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

        }
}


注意:iptables 和浏览器缓存或使ghost blog 无法正常显示。


搭建Ghost博客 环境记录_搭建Ghost博客 环境记录