Nginx 安装

1.下载nginx:

http://nginx.org/download/nginx-0.9.1.tar.gz

 

2.解压nginx下载包到 /etc/nginx/ 目录下。

3.安装依赖包:

sudo apt-get install libssl-dev
sudo apt
-get install libzb-dev
sudo apt
-get install libpcre3-dev
sudo apt
-get install libgd2-xpm-dev

4.在 /etc/nginx/ 目录下创建bash安装脚本文件 configure-install.sh,内空如下:

#! /bin/bash
VERSION=0.9.1
NAME
=nginx
./configure --with-cpu-opt=amd64 --prefix=/usr/local/$NAME --sbin-path=/usr/local/sbin/$NAME.$VERSION --conf-path=/etc/nginx/9.x/nginx.conf --pid-path=/var/run/nginx.9.x.pid --http-log-path=/var/log/nginx/9.x.access.log --error-log-path=/var/log/nginx/9.x.error.log  --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_image_filter_module  --with-http_sub_module

5.编译安装nginx:

sudo .configure-install.sh
sudo make
sudo make install

6.创建一个没有密码的nginx用户

sudo useradd nginx
sudo passwd
-d nginx

7.在/etc/init.d/下建立nginx启动脚本文件 nginx,内容如下:

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON
=/usr/local/sbin/nginx
NAME
=nginx
DESC
=nginx

test
-x $DAEMON || (echo "$DAEMON not found" && exit 0)


# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
.
/etc/default/nginx
fi

set
-e

# . /lib/lsb/init-functions

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

8.修改/etc/nginx/nginx.conf:

user nginx;
worker_processes
4;

error_log
/data/nginx_log/error.log;
pid
/var/run/nginx.pid;

events {
  worker_connections
1024;
}

http {
  include
/etc/nginx/mime.types;
  default_type application
/octet-stream;

  access_log
/data/nginx_log/access.log;

  sendfile on;
  #tcp_nopush on;

  #keepalive_timeout 0;
  keepalive_timeout 65;
  tcp_nodelay on;

  gzip on;
  gzip_min_length
1000;
  gzip_buffers
4 8k;
  gzip_types text
/plain application/x-javascript text/css application/xml;


  # the default temp dir is /usr/local/nginx set at compile time "nginx-prefix"
  proxy_temp_path /data/nginx-proxy-temp;
  # proxy_cache_path /data/nginx_cache/etwebservice levels=1:2 keys_zone=etwebservice:50m max_size=800m;
  include /etc/nginx/conf.d/*.conf;
  include
/etc/nginx/sites-enabled/*;
}

9./etc/nginx/下创建目录:

sudo mkdir conf.d
sudo mkdir sites
-enabled

10.在/usr/local/sbin下创建连接(方便升级用):

sudo ln -s nginx.0.8.35 nginx

11.创建目录:

sudo mkdir /data
sudo mkdir
/data/nginx_log

12.在/etc/nginx/sites-enabled目录,创建一个站点配置文件test,内容如下:

# You may add here your
#
server {
#
...
#
}
#
statements for each of your virtual hosts

#upstream glassfish {
#
server 127.0.0.1:8080 weight=1;
#
}


server {
# deny 221.194.132.0/24;
allow all;
listen
80;
server_name
192.168.4.174;

# if ($host != 'www.maimaijia.cn') {
#
rewrite ^/(.*)$ http://www.maimaijia.cn/$1 permanent;
#
}

access_log
/var/log/nginx/test.access.log ;

charset utf
-8;

gzip on;
gzip_min_length
500;
gzip_disable
"msie6";
gzip_types text
/plain application/x-javascript text/css text/xml text/javascript;

# location / {
#
root /home/maimaijia/web;
#
index index.html index.htm;
# error_page 403 404 /pic/nopic.jpg;
#
}

location
/favicon.ico {
rewrite ^
/favicon\.ico$ /public/images/favicon.ico permanent;
}



location
/ {
# proxy_cache 57hao;
# proxy_cache_key 57hao$request_uri;
proxy_cache_valid 60m;

proxy_pass http:
//127.0.0.1:9000;
proxy_redirect off;
proxy_set_header Host
$host:$server_port;
proxy_set_header X
-Real-IP $remote_addr;
proxy_set_header X
-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 50m;
client_body_buffer_size 256k;
proxy_connect_timeout
30;
proxy_send_timeout
30;
proxy_read_timeout
60;
proxy_buffer_size 16k;
proxy_buffers
4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
}

13.启动nginx:

sudo /etc/init.d/nginx start

14.浏览器访问 http://192.168.4.174,测试安装是否成功。

 

 

posted on 2010-12-03 14:28  迎-客-松  阅读(483)  评论(0编辑  收藏  举报

导航