zoukankan      html  css  js  c++  java
  • nginx配置基于域名的虚拟主机

    其实基于域名和基于ip的虚拟主机配置是差不多的,在配置基于ip的虚拟主机上我们只需要修改几个地方就能变成基于域名的虚拟主机,一个是要修改域名,一个是host文件直接看代码

    [root@localhost nginx]# !428
    cat conf/nginx.conf|grep -v "#"|grep -v "^$"
    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.bp1.com;   #修改这里
            location / {
                root   html;
                index  index.html index.htm index.php;
            }
            error_page  404              /404.html;
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
            location ~ .php$ {
                root           html;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
            }
        }
        server{
            listen 192.168.3.123:80;
            server_name www.bp3.com;       #修改这里
            access_log logs/bp2.access.log combined;
            location /
            {
                index index.html index.php;
                root html/bp2;
            }
            location ~ .php$ {
                root           html/bp2;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
            }
    
        }
        server{
            listen 192.168.3.125:80;
            server_name www.bp2.com;        #修改这里
            location /{
                root html/bp3;
                index index.html index.php;
            }
            location ~ .php$ {
                root           html/bp3;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
            }
        }
    #include    /opt/nginx/conf/vhosts/www.domain2.com.conf;  #这一句是包含另一个nginx虚拟机主机的配置文件,其内容类似于上面最后一个server里面的内容,去掉注释后其功能相当于新增一台虚拟主机 } [root@localhost nginx]# cat /etc/host host.conf hostname hosts hosts.allow hosts.deny [root@localhost nginx]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.3.128 www.bp1.com #随便写的 192.168.3.125 www.bp2.com 192.168.3.123 www.bp3.com [root@localhost nginx]#

    看一下效果
    这里写图片描述

  • 相关阅读:
    【PAT甲级】1128 N Queens Puzzle (20分)
    Codeforces Global Round 7D(马拉车/PAM,回文串)
    【PAT甲级】1127 ZigZagging on a Tree (30分)(已知中序后序蛇形输出层次遍历)
    SDOI2012 体育课
    APIO2018 Circle selection 选圆圈
    [科技] 求数列的前k次方和
    APIO2016 Fireworks
    CTSC2018 暴力写挂
    ZJOI2018 胖
    SDOI2017 数字表格
  • 原文地址:https://www.cnblogs.com/biaopei/p/7730516.html
Copyright © 2011-2022 走看看