手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

CentOS6.2部署Nginx虚拟主机

[日期:2012-07-18] 来源:Linux社区  作者:crazylinux [字体:大 中 小]

[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.linuxidc.com
www.linuxidc.com has address 192.168.10.1
[root@host1 ~]# host www.88181.com
www.88181.com has address 192.168.10.1
[root@host1 ~]# host www.Androidj.com
www.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   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 linuxidc.conf;
include 88181.conf;
include androidj.conf;
}
[root@host1 conf]# cat linuxidc.conf
server {
        listen  80;
        server_name     www.linuxidc.com;
        access_log      logs/linuxidc.access.log;
        location / {
                index index.html;
                root html/linuxidc.com;
        }
}
[root@host1 conf]# cat 88181.conf 
server {
        listen  80;
        server_name     www.88181.com;
        access_log      logs/88181.access.log;
        location / {
                index index.html;
                root html/88181.com;
        }
}
[root@host1 conf]# cat androidj.conf     
server {
        listen  80;
        server_name     www.androidj.com;
        access_log      logs/androidj.access.log;
        location / {
                index index.html;
                root html/androidj.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

linux
相关资讯       Nginx安装  Nginx配置 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款