CentOS6.2部署Nginx虚拟主机

[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
has address 192.168.10.1
[root@host1 ~]# host
has address 192.168.10.1
[root@host1 ~]# host Androidj.com
has address 192.168.10.1
2、创建网页存放目录
[root@host1 ~]# mkdir /data/nginx/html/domain{1,2,3}.com
[root@host1 ~]# echo "www.linuxidc.com" > /data/nginx/html/linuxidc.com/index.html
[root@host1 ~]# echo "www.88181.com" > /data/nginx/html/88181.com/index.html
[root@host1 ~]# echo "www.androidj.com" > /data/nginx/html/androidj.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   ;
        #}

# 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;

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/c91b376d50ea62c5a93aac81991ca338.html