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

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

  • 相关阅读:
    程序员无休止加班的真正原因!
    Tomcat 爆出高危漏洞!
    Spring Boot 2.3 终于要来了!
    2020 年 4月全国程序员工资出炉!
    面试官再问你如何看待义务加班,学会如何怼回去!
    如何在一分钟内搞定面试官?
    安装android studio时,解决unable to access android sdk add-on list
    poj 3230 Travel(dp)
    hdu 2059 龟兔赛跑(dp)
    解决未能启动服务“VMware Authorization Service”
  • 原文地址:https://www.cnblogs.com/biaopei/p/7730516.html
Copyright © 2011-2022 走看看