【问题标题】:How to perfectly set up virtual host for codeigniter project?如何为codeigniter项目完美设置虚拟主机?
【发布时间】:2017-09-06 17:22:43
【问题描述】:

我正在尝试为 codeigniter 项目创建一个虚拟主机。我已经在 httpd-vhosts.conf 中做到了:

    <VirtualHost *:80>
      DocumentRoot "C:\xampp\htdocs\CI_projects\facebook-login"
       ServerName dev.facebook-login.com
       <Directory "C:\xampp\htdocs\CI_projects\facebook-login">
     Require all granted
    </Directory>
    </VirtualHost>

在 application/config/config.php 中,

$config['base_url'] = 'http://dev.facebook-login.com';

$config['index_page'] = '';

浏览器打开登录页面。但是当从任何其他 uri 转换时,它会说找不到对象。 当我像这样配置 httpd-vhosts.conf 时:

   <VirtualHost *:80>
      DocumentRoot "C:\xampp\htdocs\CI_projects\facebook-login\index.php"
       ServerName dev.facebook-login.com
       <Directory "C:\xampp\htdocs\CI_projects\facebook-login\index.php">
     Require all granted
    </Directory>
    </VirtualHost>

它会出现资产问题,即图像和某些 CSS 无法加载。我该如何解决?

【问题讨论】:

    标签: php apache codeigniter uri


    【解决方案1】:

    我在 Windows 10 上,我使用 xampp 和虚拟主机,这是我设置的方式。

    在基本网址的末尾加上斜杠

    $config['base_url'] = 'http://dev.facebook-login.com/';
    

    先去

    Windows > System32 > 驱动程序 > 等 > 主机

    您可能需要以管理员身份打开才能保存

    你可能会看到类似的东西

    127.0.0.1       localhost 
    

    下面为 dev.facebook-login.com 创建另一个类似示例:

    127.0.0.1       localhost
    127.0.0.1       dev.facebook-login.com
    

    保存

    然后去

    xampp > apache > conf > extra > httpd-vhosts.conf

    以管理员身份打开,以便保存。

    DocumentRoot 上不需要 index.php

    <VirtualHost *:80>
        ##ServerAdmin webmaster@dummy-host.example.com
        DocumentRoot "C:/xampp/htdocs/CI_projects/facebook-login"
        ServerName dev.facebook-login.com
        ##ServerAlias www.dummy-host.example.com
        ##ErrorLog "logs/dummy-host.example.com-error.log"
        ##CustomLog "logs/dummy-host.example.com-access.log" common
    </VirtualHost> 
    

    保存并重启服务器。

    我将它用于我的 htaccess

    Options +FollowSymLinks
    Options -Indexes
    DirectoryIndex index.php
    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    

    【讨论】:

      【解决方案2】:

      httpd-vhosts.conf

      Listen 1122
      <VirtualHost *:1122>
      DocumentRoot "D:\laragon_server\www\hugpong_production"
      <Directory "D:\laragon_server\www\hugpong_production">
      Order allow,deny
      Allow from all
      </Directory>
      </VirtualHost>
      

      .htaccess

      <IfModule mod_rewrite.c>
      RewriteEngine On
      
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php?/$1 [L]
      </IfModule>
      

      【讨论】:

        【解决方案3】:

        https://www.namecheap.com/support/knowledgebase/article.aspx/10026/33/installing-an-ssl-certificate-on-xampp/ 自 2021 年 1 月起,php 8 还没有为 CI4 做好准备! XAMPP 在 php 7 包中预加载了 ssl 证书 额外考虑不常见的虚拟主机并将其放入其中 我唯一持久的问题是codeigniter 4路由,必须打开php spark serve才能让XAMPP路由默认索引之外的页面,没有其他工作,它的垃圾到那个程度,接下来将尝试使用composer ....一整本书需要 要写关于 codeigniter 4 路线以及为什么它们不起作用,200 页加

        DocumentRoot "C:\xampp\htdocs" 服务器名称 localhost

        <VirtualHost example.com *:8080>
             ServerName example.com
             ServerAlias www.example.com
             DocumentRoot "C:\xampp\htdocs\codeignite4\public"
           //my project folder is codeignite4 without using composer this time
           //i added listen 8080 under listen 80 in htppd.conf
            ServerName example.com  
        

        DocumentRoot "C:\xampp\htdocs\codeignite4\public" 服务器名称 example.com SSL引擎开启 SSLCertificateFile "C:/xampp/apache/conf/ssl.crt/server.crt" // 你可以验证这些文件位置,证书数据 SSLCertificateKeyFile "C:/xampp/apache/conf/ssl.key/server.key" // 不带目录标签可能有助于放入虚拟主机 要求所有授予

        这样做我能够复制原始安装,创建站点访问 使用 http://localhost:8080 或 http://example.com/ 作为我的基本网址 在我的示例中 index.php 被删除,设置为 '' 当使用命令提示符进入 codeignite4 项目文件夹时,我可以 启动 php spark serve 和路由将工作以前是 404

        【讨论】:

        • 这很难阅读和理解。考虑使用标准英语语法并添加一些formatting
        【解决方案4】:
        Using Xampp 7.3.25 Dec 2020 because php 8 will not run error
        free with codeigniter 4 as of this date, this worked for me as
        my first codeigniter 4 virtual host setup, my install had 
        difficulty initially with using port 80, seems to want to for
        port 443 if it can..I'm not a server pro but i wanted to 
        leave this for the next guy....This is strictly name based
        virtual hosts for develop, ip based would have obvious 
        advantages. Because i had trouble in initial CI4 testing with
        port 80 the (*) in virtual hosts vs (*:80) seemed to solve one 
        hurdle in searching for more ports, now i can finally begin my 
        first project ...my default URL was also changed to example.com
        in appstarter/apps/config file. Carefully reread <tags> for 
        typos, its easy to shut server down! 
        

        DocumentRoot "C:/Xampp/htdocs/" 服务器名称本地主机 要求所有授予

        DocumentRoot "C:/Xampp/htdocs/appstarter/public/" 服务器名称 example.com 服务器别名www.example.com # 可能不要尝试使用 dir 标签,关闭服务器
        # httpd.conf 中的指令似乎就足够了

        I have added a htaccess file in the appstarter/public
        I assume this is primitive, can get far more advanced 
        The Apache help pages helped me focus a bit more on 
        what i must accomplish, name based virtual hosts this case 
        
        <IfModule mod_rewrite.c>
          RewriteEngine on
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule ^(.*)$ index.php/$1 [L,QSA]
        </IfModule>
        
        
        2.2 Apache configuration:      :Apache server context important!
             Order allow,deny          :The hackers are winning..... 
             Allow from all
             
        2.4 Apache configuration:
             Require all granted
        

        【讨论】:

          猜你喜欢
          • 2019-01-23
          • 2011-05-05
          • 2020-07-17
          • 2018-07-04
          • 2018-06-27
          • 2022-10-09
          • 2016-10-08
          • 2018-08-17
          • 2013-07-16
          相关资源
          最近更新 更多