[root@host1 ~]# yum -y install gcc* openssl-devel zlib-devel make pcre pcre-devel
安装Nginx
[root@host1 ~]# tar -zxvf nginx-0.8.46.tar.gz -C /usr/src/
[root@host1 ~]# cd /usr/src/nginx-0.8.46/
[root@host1 nginx-0.8.46]# ./configure --prefix=/data/nginx --with-http_stub_status_module --with-http_ssl_module
[root@host1 nginx-0.8.46]# make
[root@host1 nginx-0.8.46]# make install
[root@host1 nginx-0.8.46]# ln -sf /data/nginx/sbin/nginx /usr/sbin/
虚拟主机配置:
1、确保DNS正常解析
[root@host1 ~]# host www.domain1.com
www.domain1.com has address 192.168.10.1
[root@host1 ~]# host www.domain2.com
www.domain2.com has address 192.168.10.1
[root@host1 ~]# host www.domain3.com
www.domain3.com has address 192.168.10.1
2、创建网页存放目录
[root@host1 ~]# mkdir /data/nginx/html/domain{1,2,3}.com
[root@host1 ~]# echo "www.domain1.com" > /data/nginx/html/domain1.com/index.html
[root@host1 ~]# echo "www.domain2.com" > /data/nginx/html/domain2.com/index.html
[root@host1 ~]# echo "www.domain3.com" > /data/nginx/html/domain3.com/index.html
3、创建配置文件
[root@host1 ~]# cd /data/nginx/conf/
[root@host1 conf]# vim nginx.conf #把server字段的内容都#掉
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#server {
# listen 80;
# server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
# location / {
# root html;
# index index.html index.htm;
# }
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# root html;
# }
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
#}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
include domain1.conf;
include domain2.conf;
include domain3.conf;
}
[root@host1 conf]# cat domain1.conf
server {
listen 80;
server_name www.domain1.com;
access_log logs/domain1.access.log;
location / {
index index.html;
root html/domain1.com;
}
}
[root@host1 conf]# cat domain2.conf
server {
listen 80;
server_name www.domain2.com;
access_log logs/domain2.access.log;
location / {
index index.html;
root html/domain2.com;
}
}
[root@host1 conf]# cat domain3.conf
server {
listen 80;
server_name www.domain3.com;
access_log logs/domain3.access.log;
location / {
index index.html;
root html/domain3.com;
}
}
[root@host1 conf]# nginx -t
the configuration file /data/nginx/conf/nginx.conf syntax is ok
configuration file /data/nginx/conf/nginx.conf test is successful
[root@host1 conf]# nginx