linux - 在 linux 上为 opencart 设置虚拟主机/多个商店

标签 linux apache opencart virtual-hosts lampp

我正在使用 Opencart 2.0,我想为第二家商店设置一个虚拟主机。我还在 Kali Linux 上使用 Xampp。我的主要商店位于 /opt/lampp/htdocs/main_store/,我用来访问它的 url 是 localhost/main_store 我在后端,我已将其 url 设置为 http:localhost/store_2。我编辑了我的 /etc/hosts 并添加了我的服务器名称

   127.0.0.1    localhost
   127.0.1.1    hostname

   127.0.0.1    localhost/store_2

我已经编辑了我的 /opt/lampp/etc/extra/http.v-hosts.conf 并添加了

  # Sub domain localhost/store_2
 <VirtualHost *:80>
    DocumentRoot "/opt/lampp/htdocs/main_store/"
    ServerName localhost/store_2

    <Directory "/opt/lampp/htdocs/main_store/">
     Options Indexes FollowSymLinks MultiViews Includes 
     AllowOverride All 
     Order allow,deny 
     Allow from all 
     </Directory>
 </VirtualHost>

当我键入 localhost/store_2 时,我收到一个对象未​​找到错误。我做错了什么?

最佳答案

第 1 步:/etc/hosts 中添加您的自定义主机。在您的终端中执行此操作

 sudo gedit /etc/hosts

然后添加您的自定义主机。例如,我的自定义主机是 mysite,所以我添加了 127.0.0.1 mysite。在您的情况下是 store_2

 127.0.0.1  localhost
 127.0.1.1  yourhostname

 127.0.0.1  mysite

第 2 步:。通过编辑 httpd.conf 启用虚拟主机

   sudo gedit /opt/lampp/etc/httpd.conf

找到 #Include etc/extra/httpd-vhosts.conf 并删除 # 以取消注释这一行

第 3 步:通过打开 httpd-vhosts.conf 文件添加新的虚拟主机

 sudo gedit /opt/lampp/etc/extra/httpd-vhosts.conf

通常,默认情况下,此文件中有两个虚拟主机。评论这些虚拟主机或删除它们。例如在我的例子中

#<VirtualHost *:80>
#ServerAdmin webmaster@dummy-host.example.com
#DocumentRoot "/opt/lampp/docs/dummy-host.example.com"
#ServerName dummy-host.example.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>

#<VirtualHost *:80>
#ServerAdmin webmaster@dummy-host2.example.com
#DocumentRoot "/opt/lampp/docs/dummy-host2.example.com"
#ServerName dummy-host2.example.com
#ErrorLog "logs/dummy-host2.example.com-error_log"
#CustomLog "logs/dummy-host2.example.com-access_log" common
#</VirtualHost>

然后添加

 NameVirtualHost 127.0.0.1
 <VirtualHost 127.0.0.1> 
   DocumentRoot /opt/lampp/htdocs/
   ServerName localhost
</VirtualHost>

<VirtualHost mysite>
    ServerAdmin webmaster@localhost
    DocumentRoot /opt/lampp/htdocs/your_project_folder/
    ServerName mysite
    ServerAlias mysite
    RewriteEngine On
    RewriteOptions inherit
    CustomLog /var/log/apache2/mysite.log combined
    <Directory /opt/lampp/htdocs/your_project_folder/>
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

在上面的代码中,您的项目文件夹是 ma​​in_store。同时将 mysite 替换为您的 store_2

第 4 步: 重新启动 XAMPP 服务器。这非常重要

    sudo /opt/lampp/lampp restart

第 5 步:在浏览器的地址栏中键入 http://mysite/,它应该可以运行。在你的情况下 http://store_2/

关于linux - 在 linux 上为 opencart 设置虚拟主机/多个商店,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42154939/

相关文章:

mysql - 在mysql查询中包含批发字段

linux - 在 Bash 中,如何在每行后面添加文字\n?

linux - 了解 qemu-kvm

java - 使用 apache POI 读取 ms excel 时不保留前导零

apache - WebSVN 抛出 XML 错误 : no element found (3) after upgrading to SVN 1. 8.8

javascript - .js 文件修改不适用于 ocmod opencart

mysql - 从数据库上传的产品未列出-opencart

Linux:在 shell 脚本中导出环境变量,使其在任何服务器上都灵活

linux - 从 usr/include 中删除一个文件?

java - Apache tomcat 服务器显示 java.lang.NoSuchMethodException