xampp+nginx环境搭建

一、安装软件

安装xampp,下载好nginx(官网stable最新版本 nginx/Windows-1.14.0),放在xampp目录下。

二、配置环境

1、在D:\xampp\apache\conf\extra\httpd-vhosts.conf中配置如下

注意不要添加换行空格,容易出错。

8108、8109是我要用的两个端口,一个是网站后台,一个是微信小程序后台,所以配置了两个。

如果你要使用,请替换 DocumentRoot 、ServerName 、Directory 三个地方。

################################## 以下是微信小程序后台
<VirtualHost *:8108>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "D:/Projects/Cdd/System/Public"
    ServerName wechat.cdd.com
    ErrorLog "logs/dummy-host2.example.com-error.log"
    CustomLog "logs/dummy-host2.example.com-access.log" common
    
    <Directory "D:/Projects/Cdd/System/Public">
        #Options Indexes FollowSymLinks
        AllowOverride all
        Require local
        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !^.*\.(js|css|ico|gif|jpg|jpeg|png|swf|txt)$
        RewriteRule ^(.*)$ index.php [L]
    </Directory>
</VirtualHost>

################################## 以下是网站后台
<VirtualHost *:8109>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "D:/Projects/Cdd/Wechat/Public"
    ServerName system.cdd.com
    ErrorLog "logs/dummy-host2.example.com-error.log"
    CustomLog "logs/dummy-host2.example.com-access.log" common
    
    <Directory "D:/Projects/Cdd/Wechat/Public">
        #Options Indexes FollowSymLinks
        AllowOverride all
        Require local
        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !^.*\.(js|css|ico|gif|jpg|jpeg|png|swf|txt)$
        RewriteRule ^(.*)$ index.php [L]
    </Directory>
</VirtualHost>

2、在D:\xampp\apache\conf\httpd.conf中注释掉监听80的端口,添加这两个的监听端口。   

Listen 8108
Listen 8109

3、C:\Windows\System32\drivers\etc\hosts文件中添加域名:   

127.0.0.1           wechat.Cdd.com
127.0.0.1           system.Cdd.com

4、配置nginx/conf中的nginx.conf文件。

    (1)在第一个server前添加以下代码:    

upstream ServerMachines_cdd_System{
      server 127.0.0.1:8108;
}
upstream ServerMachines_cdd_Wechat{
      server 127.0.0.1:8109;
}

    (2)在第一个server后添加配置:   

############################################################### cdd.system
    server{
        listen       80;
        server_name  system.cdd.com;

        location / {
            proxy_pass   http://ServerMachines_cdd_System;
            proxy_redirect     off;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        }

        location ~ .*\.(html)$ {
            root D:/Projects/Cdd/Cache/System/Html/;
            if (-f $request_filename) {
              expires 1d;
              break;
            }
        }

        location ^~ /Common/ {
            root D:/Projects/Cdd/Cache/;
            if (-f $request_filename) {
              expires 1d;
              break;
            }
        }

        location ^~ /Uploads/ {
            root D:/Projects/Cdd/Cache/;
            if (-f $request_filename) {
              expires 1d;
              break;
            }
        }

        location ^~ /Downloads/ {
            root D:/Projects/Cdd/Cache/;
            if (-f $request_filename) {
              expires 1d;
              break;
            }
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css|xml|ttf|woff|svg|eot|cab)$ {
            root D:/Projects/Cdd/Cache/System/;
            if (-f $request_filename) {
              expires 1d;
              break;
            }
         }

         #防盗链
        location ~* \.(gif|jpg|swf)$ {
            valid_referers none blocked start.igrow.cn sta.igrow.cn;
            if ($invalid_referer) {
                rewrite ^/ http://$host/logo.png;
            }
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
       
        location ~ \.php$ {
            proxy_pass   http://ServerMachines_cdd_System;
            proxy_redirect     off;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        }
    }

############################################################### cdd.wechat
    server{
        listen       80;
        server_name  wechat.cdd.com;

        location / {
            proxy_pass   http://ServerMachines_cdd_Wechat;
            proxy_redirect     off;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        }

        location ~ .*\.(html)$ {
            root D:/Projects/Cdd/Cache/Wechat/Html/;
            if (-f $request_filename) {
              expires 1d;
              break;
            }
        }

        location ^~ /Common/ {
            root D:/Projects/Cdd/Cache/;
            if (-f $request_filename) {
              expires 1d;
              break;
            }
        }

        location ^~ /Uploads/ {
            root D:/Projects/Cdd/Cache/;
            if (-f $request_filename) {
              expires 1d;
              break;
            }
        }

        location ^~ /Downloads/ {
            root D:/Projects/Cdd/Cache/;
            if (-f $request_filename) {
              expires 1d;
              break;
            }
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css|xml|ttf|woff|svg|eot|cab)$ {
            root D:/Projects/Cdd/Cache/Wechat/;
            if (-f $request_filename) {
              expires 1d;
              break;
            }
         }

         #防盗链
        location ~* \.(gif|jpg|swf)$ {
            valid_referers none blocked start.igrow.cn sta.igrow.cn;
            if ($invalid_referer) {
                rewrite ^/ http://$host/logo.png;
            }
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
       
        location ~ \.php$ {
            proxy_pass   http://ServerMachines_cdd_Wechat;
            proxy_redirect     off;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        }
    }

5、接着配置数据库。在svn中拉取到sql文件后,在navicat里localhost新建数据库,命名随意,右键选择execute batch file,找到sql文件的目录,勾选跳过error,进行导入。

6、另外还要在D:\Projects\Square\System\Application\Common\Conf添加dev01.php脚本,才能连上本地数据库。如果你要使用,可以修改 host= 后面写你的数据库IP地址,dbname= 后面写数据库名称,DB_USER 后面写登录名,DB_PWD 后面写数据库密码。

<?php
return array(

    'DB_TYPE' => 'pdo',

// 注意DSN的配置针对不同的数据库有所区别 请参考PHP手册PDO类库部分

'DB_DSN'=> 'mysql:host=localhost;dbname=square',

'DB_USER'=>'root',

'DB_PWD'=>'',

    // 'DB_DSN' => 'mysql:host=127.0.0.1;dbname=car',

    // 'DB_USER' => 'root',

    // 'DB_PWD' => '',

//'DB_PREFIX'=>'think_',

// 其他项目配置参数………

);

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值