|
[root@web01~]# yum install pcre pcre-devel -y(下载依赖库)
[root@web01 ~]# yum install openssl-devel -y(https加密服务会用到)
[root@web01~]# rpm -qa pcre pcre-devel(检查)
pcre-devel-7.8-7.el6.x86_64
pcre-7.8-7.el6.x86_64
[root@web01~]# rpm -qa openssl openssl-devel
openssl-devel-1.0.1e-42.el6.x86_64
openssl-1.0.1e-42.el6.x86_64
useradd nginx -M -s /sbin/nologin(建立虚拟用户,-M不创建家目录,不允许登录)
id nginx(检查虚拟用户)
mkdir -p /application/tools(创建目录)
cd /application/tools(切换目录)
rz(上传压缩包,上传到的目录为当前所在目录)
tar xf nginx-1.6.3.tar.gz (解压)
cd nginx-1.6.3
./configure--prefix=/application/nginx-1.6.3 --user=nginx --group=nginx--with-http_ssl_module --with-http_stub_status_module(初始化数据库)
make && make install(编译并安装)
echo $?(检验编译是否成功,输出为0表示正常,1为不正常)
ln -s /application/nginx-1.6.3/ /application/nginx(创建软连接,不要是用rm-rf删除软连接,会把软连接下面的目录删除的)
[root@web01~]# /application/nginx/sbin/nginx -h(帮助文件)
nginxversion: nginx/1.6.3
Usage:nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen,> -p prefix : set prefix path (default: /application/nginx-1.6.3/)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out ofconfiguration file
[root@web01~]# /application/nginx/sbin/nginx -V(显示编译参数)
nginxversion: nginx/1.6.3
built bygcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
TLS SNIsupport enabled
configurearguments: --prefix=/application/nginx-1.6.3 --user=nginx --group=nginx--with-http_ssl_module --with-http_stub_status_module
[root@web01~]# cd /application/nginx/conf/(打开配置文件所在目录)
egrep -v "#|^$" nginx.conf.default >nginx.conf(去掉杂项,nginx.conf.default文件为nginx默认配置文件)
[root@web01 conf]# vim nginx.conf(d+G为全部删除光标以下内容)
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name www.etiantian.org;
location / {
root html/www;
index index.html index.htm;
}
}
server {
listen 80;
server_name bbs.etiantian.org;
location / {
root html/bbs;
index index.html index.htm;
}
}
server {
listen 80;
server_name blog.etiantian.org;
location / {
root html/blog;
index index.html index.htm;
}
}
}
"nginx.conf"35L, 764C 已写入
mkdir -p ../html/{www,blog,bbs}(创建站点目录文件)
for n in www bbs blog;do echo "$n.etiantian.org" > ../html/$n/index.html;done(创建主页并写入内容)
C:\Windows\System32\drivers\etc\hosts(物理机hosts添加下面解析)
10.0.0.8 www.etiantian.org etiantian.org blog.etiantian.org bbs.etiantian.org
以下为简化主配置文件
[root@web01 conf]# mkdir /application/nginx/conf/extra(建立extra目录)
[root@web01conf]# cat -n nginx.conf(查看行数)
1 worker_processes 1;
2 events {
3 worker_connections 1024;
4 }
5 http {
6 include mime.types;
7 default_type application/octet-stream;
8 sendfile on;
9 keepalive_timeout 65;
10 server {
11 listen 80;
12 server_name www.etiantian.org;
13 location / {
14 root html/www;
15 index index.html index.htm;
16 }
17 }
18 server {
19 listen 80;
20 server_name bbs.etiantian.org;
21 location / {
22 root html/bbs;
23 index index.html index.htm;
24 }
25 }
26 server {
27 listen 80;
28 server_name blog.etiantian.org;
29 location / {
30 root html/blog;
31 index index.html index.htm;
32 }
33 }
34 }
35
[root@web01conf]# sed -n '10,17p' nginx.conf >extra/www.conf(追加并创建各自站点配置文件)
[root@web01conf]# cat extra/www.conf(检查配置文件)
server {
listen 80;
server_name www.etiantian.org;
location / {
root html/www;
index index.html index.htm;
}
}
[root@web01conf]# sed -n '18,25p' nginx.conf >extra/bbs.conf
[root@web01conf]# cat extra/bbs.conf
server {
listen 80;
server_name bbs.etiantian.org;
location / {
root html/bbs;
index index.html index.htm;
}
}
[root@web01conf]# sed -n '26,33p' nginx.conf >extra/blog.conf
[root@web01conf]# cat extra/blog.conf
server {
listen 80;
server_name blog.etiantian.org;
location / {
root html/blog;
index index.html index.htm;
}
}
[root@web01conf]# vim nginx.conf(简化主配置文件)
worker_processes 1;
error_log logs/error.log error;(指定错误日志,相对路径为nginx安装目录,具体为/application/nginx/logs/error.log)
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
log_format main '$remote_addr - $remote_user[$time_local] "$request" '(日志文件)
'$status $body_bytes_sent"$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#nginx vhosts config(各站点配置添加)
include extra/www.conf;
include extra/bbs.conf;
include extra/blog.conf;
include extra/status.conf;(检查模块)
}
~
~
[root@web01conf]# cat >>/application/nginx/conf/extra/status.conf |
|
|