zoukankan      html  css  js  c++  java
  • 简单的 nginx 多站点配置

    测试环境:基于CentOS6.8 编译安装LNMPhttp://www.cnblogs.com/afee666/p/6836161.html)

    一 需求

    在一个 VPS 主机上配置 web 服务器,实现通过一个 IP 访问多个站点或域名。

    假设:

    IP地址: 66.88.33.11

    域名1 test1.example.com 放在 /web/www/test1

    域名2 test2.example.com 放在 /web/www/test2

    二 思路

    2.1 把2个站点 test1.example.com, test2.example.com 放到 nginx 可以访问的目录 /web/www/

    2.2 给每个站点分别创建一个 nginx 配置文件 test1.conf,test2.conf,并把配置文件放到 /etc/nginx/vhosts/ 下

    2.3 在 /etc/niginx/nginx.conf 里面加一句 include 把步骤2创建的配置文件全部包含进来(用 * 号),重启 nginx

    三 实现

    3.1 在 /etc/nginx 下创建 vhosts 目录

    mkdir /etc/nginx/vhosts

    3.2 在 /etc/nginx/vhosts/ 里创建一个名字为 test1.conf 的文件,把以下内容拷进去

    server {
           listen       80;
           server_name test1.example.com;
           index index.html index.htm index.php;
           root /web/www/test1;
           location ~ .*.(php|php5)?$
           {
                   #fastcgi_pass  unix:/tmp/php-cgi.sock;
                   fastcgi_pass  127.0.0.1:9000;
                   fastcgi_index index.php;
                   include fastcgi.conf;
           }
           location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
           {
                    expires 30d;
           }
           location ~ .*.(js|css)?$
           {
                    expires 1h;
           }
           include /web/server/nginx/conf/rewrite/test1.conf;
           access_log  /web/log/nginx/access/conf.log;
    }
    View Code

    3.3 在 /etc/nginx/vhosts/ 里创建一个名字为 test2.conf 的文件,把以下内容拷进去

    server {
           listen       80;
           server_name test2.example.com;
           index index.html index.htm index.php;
           root /web/www/test2;
           location ~ .*.(php|php5)?$
           {
                   #fastcgi_pass  unix:/tmp/php-cgi.sock;
                   fastcgi_pass  127.0.0.1:9000;
                   fastcgi_index index.php;
                   include fastcgi.conf;
           }
           location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
           {
                    expires 30d;
           }
           location ~ .*.(js|css)?$
           {
                    expires 1h;
           }
           include /web/server/nginx/conf/rewrite/test2.conf;
           access_log  /web/log/nginx/access/test2.log;
    }
    View Code

    3.4 打开 /etc/nginx/nginix.conf 文件,在 http 模块中加入 include 把以上2个文件包含进来

     include /etc/nginx/vhosts/*;
  • 相关阅读:
    在controller间分享数据(第一种办法)
    AngularJS之Factory vs Service vs Provider
    directive和controller如何通信
    AngularJS 之Services讲解
    AngularJS心得体会
    int 和Integer
    2019天梯赛练习题(L2专项练习)
    2019天梯赛练习题(L1专项练习)
    Hash冲突的几种解决方法
    HashMap
  • 原文地址:https://www.cnblogs.com/afee666/p/6839947.html
Copyright © 2011-2022 走看看