一:安装环境:redhat5.4 平台
(1)安装依赖包:
gcc,openssl-devel,pcre-devl,zlib-devel软件库。
(2)安装Nginx所需的pcre-devel库
tar -zxvf pcre-8.02.tar.gz
cd pcre-8.02
./configure
make
make install
(3)安装Nginx
tar -zxvf nginx-0.7.65.tar.gz
cd nginx-0.7.65
./configure --with-http_gzip_static_module --with-http_stub_status_module --without-http_gzip_module --prefix=/opt/nginx
make
make install
检查Nginx配置文件是否正常:
/opt/nginx/sbin/nginx -t
the configuration file /opt/nginx/conf/nginx.conf syntax is ok
configuration file /opt/nginx/conf/nginx.conf test is successful
启动Nginx服务:
/opt/nginx/sbin/nginx
关闭Nginx服务:
kill xxx pid号
到此Nginx安装完成
注明:搭建一个DNS服务作为解析,在DNS做三条A记录和反向解析。
域名如下:
(1):test1.test.com
(2):test2.test.com
(3):test3.test.com
注明:创建三个网页文件作为测试:
mkdir -p /web/www/test1
mkdir -p /web/www/test2
mkdir -p /web/www/test3
touch /web/www/test1/index.html
touch /web/www/test2/index.html
touch /web/www/test3/index.html
网页内容随便写即可!
二:虚拟主机配置
cd /opt/nginx/conf
vim nginx.conf
1
2 user nobody; 指定Nginx进程运行用户及组
3 worker_processes 1; 指定Nginx要开启的进程数
4
5 #error_log logs/error.log;
6 #error_log logs/error.log notice;
7 error_log logs/error.log debug; 定义全局错误日志文件:debug输出日志最为详细。
8
9 pid logs/nginx.pid; 指定进程id的存储文件位置
10
11
12 events {
13 use epoll; 指定Nginx工作模式:不同的是opoll用在linux平台上。
14 worker_connections 1024; 定义Nginx进程的最大连接数
15 }
16
17
18 http {
19 include mime.types; 实现对配置文件所有包含文件的设定,减少主配置文件的复杂性。
20 default_type application/octet-stream;
21
22 log_format main '$remote_addr - $remote_user [$time_local] "$request" '
23 '$status $body_bytes_sent "$http_referer" '
24 '"$http_user_agent" "$http_x_forwarded_for"';
25
26 # access_log logs/access.log main;
27 client_max_body_size 20m; 设置允许客户端请求的最大的单个文件字节数。
28 client_header_buffer_size 32k;
29 large_client_header_buffers 4 32k;
30 sendfile on; 开启高效文件传输模式
31 tcp_nopush on; on用于防止网络堵塞
32 tcp_nodelay on; on用于防止网络堵塞
33
34 #keepalive_timeout 0;
35 keepalive_timeout 65;
36
37 gzip on;
38
39 server {
40 listen 80;
41 server_name test1.test.com;
42
43 #charset koi8-r;
44
45 access_log logs/test1.access.log main;
46
47 location / {
48 root /web/www/test1;
49 index index.html index.htm;
50 }
51
52 error_page 404 /404.html;
53
54 # redirect server error pages to the static page /50x.html
55 #
56 error_page 500 502 503 504 /50x.html;
57 location = /50x.html {
58 root html;
59 }
60
61 # proxy the PHP scripts to Apache listening on 127.0.0.1:80
62 #
63 #location ~ \.php$ {
64 # proxy_pass http://127.0.0.1;
65 #}
66
67 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
68 #
69 #location ~ \.php$ {
70 # root html;
71 # fastcgi_pass 127.0.0.1:9000;
72 # fastcgi_index index.php;
73 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
74 # include fastcgi_params;
75 #}
76
77 # deny access to .htaccess files, if Apache's document root
78 # concurs with nginx's one
79 #
80 #location ~ /\.ht {
81 # deny all;
82 #}
83 }
84
85
86 # another virtual host using mix of IP-, name-, and port-based configuration
87 #
88 #server {
89 # listen 8000;
90 # listen somename:8080;
91 # server_name somename alias another.alias;
92
93 # location / {
94 # root html;
95 # index index.html index.htm;
96 # }
97 #}
98
99 # 配置虚拟主机
100 server {
101 listen 80;
102 server_name test2.test.com;
103
104 location / {
105 root /web/www/test2;
106 index index.html index.htm;
107 charset gb2312;
108 access_log logs/test2.access.log main;
109 }
110 }
111 # 配置虚拟主机
112 server {
113
114 listen 80;
115 server_name test3.test.com;
116
117 location / {
118 root /web/www/test3;
119 index index.html index.htm;
120 charset gb2312;
121 access_log logs/test3.access.log main;
122 }
123 }
124
125 # HTTPS server
126 #
127 #server {
128 # listen 443;
129 # server_name localhost;
130
131 # ssl on;
132 # ssl_certificate cert.pem;
133 # ssl_certificate_key cert.key;
134
135 # ssl_session_timeout 5m;
136
137 # ssl_protocols SSLv2 SSLv3 TLSv1;
138 # ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
139 # ssl_prefer_server_ciphers on;
140
141 # location / {
142 # root html;
143 # index index.html index.htm;
144 # }
145 #}
146
147 }
148
:wq 保存
测试:
http://test1.test.com
http://test2.test.com
http://test3.test.com
本文出自 “dsafsa_技术博客” 博客,转载请与作者联系!