Apache vhost配置

时间:2017-12-20 17:00:26

标签: apache

任何人都可以帮助设置apache如何在外部公共IP的不同端口上提供多个应用程序? 我当前的主机配置

<VirtualHost *:80>
    ServerAdmin devops57@gmail.com
    DocumentRoot "C:/xampp/htdocs/"
    ServerName localhost.com
    ServerAlias www.localhost.com
    ErrorLog "logs/localhost.com-error.log"
    CustomLog "logs/localhost.com-access.log" common
</VirtualHost>


<VirtualHost *:8888>
    ServerAdmin devops57@gmail.com
    DocumentRoot "C:/xampp/htdocs/litebridge/public"
    ServerName litebridge.com
    ServerAlias www.litebridge.com
    ErrorLog "logs/litebridge.com-error.log"
    CustomLog "logs/litebridge.com-access.log" common
</VirtualHost>

由于

2 个答案:

答案 0 :(得分:0)

要让Apache在多个端口上侦听,您应该使用Listen directive

Listen 80
Listen 8888

<VirtualHost *:80>
    ServerAdmin devops57@gmail.com
    DocumentRoot "C:/xampp/htdocs/"
    ServerName localhost.com
    ServerAlias www.localhost.com
    ErrorLog "logs/localhost.com-error.log"
    CustomLog "logs/localhost.com-access.log" common
</VirtualHost>


<VirtualHost *:8888>
    ServerAdmin devops57@gmail.com
    DocumentRoot "C:/xampp/htdocs/litebridge/public"
    ServerName litebridge.com
    ServerAlias www.litebridge.com
    ErrorLog "logs/litebridge.com-error.log"
    CustomLog "logs/litebridge.com-access.log" common
</VirtualHost>

答案 1 :(得分:0)

首先,如果您的域名litebridge.com是真实的并且DNS服务器指向您的IP地址,则您不需要使用单独的端口号。

Apache将查看传入请求中的域名,并通过将其与虚拟主机定义进行比较来确定要投放的站点。

其次,您需要告诉Apache,允许在<Directory>部分中接受连接以及这些连接的来源。 在这里,我假设localhost只能从运行服务器的PC访问,所以我使用了Require local。并且litebridge.com可以从任何地方访问,因此我使用了Require all granted

<VirtualHost *:80>
    ServerAdmin devops57@gmail.com
    ServerName localhost
    ServerAlias localhost
    DocumentRoot "C:/xampp/htdocs/"
    <Directory  "C:/xampp/htdocs/">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require local
    </Directory>
    ErrorLog "logs/localhost.com-error.log"
    CustomLog "logs/localhost.com-access.log" common
</VirtualHost>


<VirtualHost *:80>
    ServerAdmin devops57@gmail.com
    DocumentRoot "C:/xampp/htdocs/litebridge/public"
    ServerName litebridge.com
    ServerAlias www.litebridge.com

    <Directory  "C:/xampp/htdocs/litebridge/public/">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog "logs/litebridge.com-error.log"
    CustomLog "logs/litebridge.com-access.log" common
</VirtualHost>