AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[virtualhost](server)

Martin Hope
edwarddeath
Asked: 2023-03-20 17:33:49 +0800 CST

Apache vHosts - 两个域、多个子域和默认值可能吗?

  • 5

经过一段时间的搜索和试错后,我得出的结论是我的问题对于谷歌来说有点太特殊了:-)

我有 2 个域和多个子域

例子.org

  • cloud.example.org
  • wiki.example.org
  • *.example.org(该域的所有其他域)应重定向到显示“建设中”图像的 example.org。

贝斯皮尔.de

  • blog.beispiel.de
  • 同样在这里:*.beispiel.de 应该重定向到 beispiel.de

我的 Apache conf 中每个子域有 1 个文件和 1 个 vHost。我对 https 使用“让我们加密”。

 

问题:

http://blupp.example.com转到 http s ://blupp.example.com 并且 Firefox 显示连接不安全警告。点击忽略后,它会重定向到主页,但URL 中带有https://blupp.example.com 。

->错误它应该转到 example.com

 

另一个问题是:

example.com 是我的第一页。所以如果…… 在 beispiel.de 出错,它重定向到第一页:cloud.example.com

->错误我不想混合使用 example.com 和 beispiel.de,但只想租用一台服务器 :-)

 

这些是我的文件(顺序很重要,我知道 :-)

0_redirects.conf 只做 http 请求 -> https

<VirtualHost *:80>
    RewriteEngine On

    RewriteCond %{HTTPS} off
    RewriteRule "/" https://%{HTTP_HOST}%{REQUEST_URI}

</VirtualHost>

1_cloud-le-ssl.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>

    ServerAdmin admin@... 
    ServerName cloud.example.com
    ServerAlias cloud.example.com

    <Directory /var/www/example.com/cloud/>
        Require all granted
        AllowOverride All
        Options FollowSymLinks MultiViews
    </Directory>

    SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf  

</VirtualHost>
</IfModule>

wiki.example.com和blog.beispiel.de相同,每个都有一个递增的前缀数字。

我首先尝试让所有 example.com 页面运行,所以我保持 beispiel.de 不变。

现在我尝试了很多方法来为两个主要域创建一个额外的虚拟主机,将其他所有内容重定向到正确的主要示例或beispiel,但失败了。

我试图重定向

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName null
    ServerAlias *.example.com
    Redirect permanent / example.com

</VirtualHost>
</IfModule>

并将此配置设置在更高阶位置 (100)。

我不知道在这里做什么。有人可以帮忙吗?

此致

埃迪

virtualhost
  • 1 个回答
  • 43 Views
Martin Hope
Powerriegel
Asked: 2023-02-10 06:25:25 +0800 CST

Apache2 VHOST 匹配错误的服务器名称

  • 5

我在 Debian Bullseye 上运行 Apache 2.4.54 并配置了 42 个 VHOST。其中大部分是我们主域的子域 xxx.my.domain.com,比如 my.domain.com。一个客户有一个特殊的域。还有一个默认的 VHOST 来捕获所有请求。所有 VHOSTS 都驻留在编号的文件中,默认排在最后。

  • HTTP -> HTTPS
  • 之前未捕获子域 -> ErrorDocument
  • 没有子域 -> errorDocument

在我刚刚输入https://my.domain.com 的情况下,这个请求被早期的虚拟主机之一捕获,而不是被默认的 VHOST 捕获。我不明白为什么会这样。

没有 SSL,请求由 99-default.conf 应答

99-default.conf

<VirtualHost _default_:80>
        ServerName my.domain.com
        Redirect permanent / https://my.domain.com
        ErrorLog ${APACHE_LOG_DIR}/default_error.log
        CustomLog ${APACHE_LOG_DIR}/default_access.log vhost_combined
</VirtualHost>

<VirtualHost *:80>
        ServerAlias *.my.domain.com
        Redirect 404 /
        DocumentRoot /var/www/html/
        ErrorDocument 404 "Subdomain does not exist"
        ErrorLog ${APACHE_LOG_DIR}/default_error.log
        CustomLog ${APACHE_LOG_DIR}/default_access.log combined
</VirtualHost>



# match requests without subdomain
<VirtualHost _default_:443>
        ServerName my.domain.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        Redirect 404 /
        ErrorDocument 404 "Please choose subdomain"
        ErrorLog ${APACHE_LOG_DIR}/default_error.log
        CustomLog ${APACHE_LOG_DIR}/default_access.log combined
</VirtualHost>

# match any subdomain that does not exist (that's why order is important)
<VirtualHost *:443>
        ServerAlias *.my.domain.com
        Redirect 404 /
        DocumentRoot /var/www/html/
        ErrorDocument 404 "Subdomain does not exist"
        ErrorLog ${APACHE_LOG_DIR}/default_error.log
        CustomLog ${APACHE_LOG_DIR}/default_access.log combined
</VirtualHost>

02-app-customer.conf

<VirtualHost *:443>
    Protocols h2 http/1.1
    ServerAlias customers-domain.com
#    ServerAlias customer.my.domain.com

    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/wildcard.crt
    SSLCertificateKeyFile /etc/ssl/private/wildcard.key
    SSLCertificateChainFile /etc/ssl/certs/wildcard_chain.crt

    ErrorLog ${APACHE_LOG_DIR}/app_error.log
    CustomLog ${APACHE_LOG_DIR}/app_access.log vhost_combined

    Include conf.d/security.conf
    Include /usr/local/app/local/customer/httpd.conf

    <FilesMatch ".+\.ph(p[3457]?|t|tml)$">
        SetHandler "proxy:unix:/run/php/php7.4-fpm-app.sock|fcgi://localhost"
    </FilesMatch>

</VirtualHost>

# Redirection from port 80 to 443 if ssl enabled
<VirtualHost *:80>
    ServerName customers-domain.com
#    ServerAlias customer.my.domain.com
    Redirect permanent / https://www.customers-domain.com/
    ErrorLog ${APACHE_LOG_DIR}/app_error.log
    CustomLog ${APACHE_LOG_DIR}/app_access.log vhost_combined
</VirtualHost>

# Redirect of www.customers-domain.com to customers-domain.com
<VirtualHost *:443>
    Protocols h2 http/1.1
    ServerName www.customers-domain.com
    ServerAlias www.customers-domain.biz
    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/wildcard.crt
    SSLCertificateKeyFile /etc/ssl/private/wildcard.key
    SSLCertificateChainFile /etc/ssl/certs/wildcard_chain.crt
    ErrorLog ${APACHE_LOG_DIR}/app_error.log
    CustomLog ${APACHE_LOG_DIR}/app_access.log vhost_combined
    Redirect permanent / https://customers-domain.com        
</VirtualHost>
<VirtualHost *:80>
    ServerName www.customers-domain.com
    ServerAlias www.customers-domain.biz
    Redirect permanent / https://customers-domain.com/
    ErrorLog ${APACHE_LOG_DIR}/app_error.log
    CustomLog ${APACHE_LOG_DIR}/app_access.log vhost_combined
</VirtualHost>

我不明白为什么02-app-customer.conf 而不是 99-default.conf 捕获了对https://my.domain.com的请求。有任何想法吗?

virtualhost
  • 1 个回答
  • 22 Views
Martin Hope
Jeff
Asked: 2022-03-05 14:48:12 +0800 CST

将许多 VirtualHosts 合并到一个块中,这是 SetEnvIf 的工作吗?

  • 1

编辑我认为我需要的是SetEnvIf

为了方便起见,我试图将我所有的端口 80 虚拟主机合并到一个块中,但我正在努力解决最后一块难题。

所有端口 80 的虚拟主机都接受一个www和non-www连接到/.well-known/acme-challenge/. 所有其他请求 301 到https://example.com/ - 没有 www。

我想我需要%{HTTP_HOST}变成一个可以定义的变量减去可能的“www”,例如${SITE}。

或者也许有更好的方法?

这是我目前所处的位置:

<VirtualHost ${IP1}:80>
    Define SITE hmmm
    ServerName example-1.com
    ServerAlias www.example-1.com
    ServerAlias example-2.com
    ServerAlias www.example-2.com
    # And so on... 25 vhosts
    DocumentRoot /home/user/htdocs/${SITE}

    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^/\.well\-known/acme\-challenge/
    RewriteRule ^ https://${SITE}%{REQUEST_URI} [NE,R=301,L]

    <Directory /home/user/htdocs/${SITE}>
        Options FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>
virtualhost mod-rewrite apache-2.4
  • 1 个回答
  • 54 Views
Martin Hope
EpF
Asked: 2022-03-04 04:28:04 +0800 CST

为什么虚拟主机出错时 htdocs 不显示目录?

  • 0

我刚刚在新的 Windows 机器上设置了 Apache v2.4、PHP 和 MySQL。我只对httpd.conf. 我包括httpd-vhosts.conf,它定义了 2 个自定义站点(我从中删除了默认dummy站点),它们都是 WordPress 站点。

其中一个 WordPress 站点没有数据库,当我转到htdocs根目录时,我看到该站点的数据库连接错误。当我注释掉DocumentRoot虚拟主机的行时,目录列表再次出现。

以下是(按顺序)的所有 -Directory相关行:httpd.conf

Define SRVROOT "C:/webserv/Apache24"

ServerRoot "${SRVROOT}"

<Directory />
    AllowOverride none
    Require all denied
</Directory>

DocumentRoot "${SRVROOT}/htdocs"
<Directory "${SRVROOT}/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

<Directory "${SRVROOT}/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

这是导致问题的虚拟主机:

<VirtualHost *:80>#gutenberg
    DocumentRoot "${SRVROOT}/htdocs/gutenberg"
    ServerName gutenberg.squarestarmedia.ie
    ErrorLog "logs/gutenberg.localhost-error.log"
</VirtualHost>

(请注意,我使用我的hosts文件指向 ServerName)。

我应该提到我正在htdocs从不同的驱动器对目录进行符号链接,但是我在另一台没有遇到相同问题的 Windows 机器上进行了非常相似的设置。

如何修复它以便htdocs始终显示目录列表,即使子目录/虚拟主机有错误?

indexes virtualhost apache-2.4
  • 1 个回答
  • 213 Views
Martin Hope
kraligor
Asked: 2022-02-28 04:30:20 +0800 CST

Apache 通过相同的域名使站点可用于 Intranet 和 Internet

  • 0

这可能是一个愚蠢的问题,但我似乎无法找到解决方案。

以下场景: https ://sub.doma.in:443托管在我家中的 Apache 服务器上。从外部连接时效果很好。从我的计算机上的同一网络连接时也很有效。但是,我的手机无法从同一网络连接 (ERR_CONNECTION_TIMED_OUT)。所以一定有什么地方不对劲。

我想要:要与 sub.doma.in 建立任何连接,请通过 Internet 访问我的托管站点。我认为这就是目前的情况,但它不适用于所有设备。

或者(最好):要从 Intranet 连接到 sub.doma.in,直接连接到内部 IP,而无需先路由到外部。

每个人都应该总是在同一个站点结束,无论他们从哪里连接。

防火墙允许来自任何地方的 80 和 443,路由器仅打开端口 443。如果您需要任何配置文件或日志,请告诉我。很感谢任何形式的帮助!:)

我当前的网站虚拟主机如下所示:

<VirtualHost *:80>

    ServerName sub.doma.in

    Alias /.well-known/acme-challenge/ /usr/share/webapps/acme

    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^/\.well\-known/acme\-challenge/
    RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]

</VirtualHost>

<VirtualHost *:443>

    ServerName sub.doma.in

    SSLEngine on
    SSLCertificateFile xxx
    SSLCertificateKeyFile xxx
    Include xxx

        Protocols h2 http/1.1

        Header always set Strict-Transport-Security "max-age=63072000"

    CustomLog "xxx" common

    DocumentRoot xxx
    DirectoryIndex index.php index.html

    <Directory xxx>
        Require all granted
                AllowOverride All
                Options FollowSymLinks MultiViews
    </Directory>

    <IfModule mod_dav.c>
        Dav off
    </IfModule>

    <FilesMatch \.php$>
        SetHandler "proxy:unix:xxx|fcgi://localhost/"
    </FilesMatch>

</VirtualHost>

virtualhost apache-2.4
  • 2 个回答
  • 176 Views
Martin Hope
AdamJones
Asked: 2022-02-16 08:54:24 +0800 CST

我可以让虚拟主机上的文件夹访问另一个虚拟主机中的站点吗?

  • 0

我在一个域上运行了两个网站代码库,如下所示

www.example.com (一个 WordPress 站点)存在于:/var/www/example.com/public_html

whitelabel.example.com(一个 Laravel 站点)存在于:/var/www/whitelabel.example.com/public_html

从服务器文件夹结构中可以看出,它们保存在两个不同的虚拟主机中。

我们需要开始对我们的主要网站进行国际语言翻译,使用我们的白标代码库是有意义的。这意味着当用户访问www.example.com/de/时,我希望它由 Laravel 代码库处理。

请注意,出于 SEO 目的,不发生重定向至关重要。

因此,如果白标网站有一个页面,例如 test,我希望www.example.com/de/test/可以访问,而不会发生任何类型的重定向。

在 Apache 下我想做的事情是可能的,还是违背了平台架构如何工作的基本思想?

这是一个 ISP 提供的 VPS 平台,我能做的改变是有限的。我能为此做些什么吗?

virtualhost .htaccess
  • 1 个回答
  • 37 Views
Martin Hope
BlueDogRanch
Asked: 2022-02-10 10:10:18 +0800 CST

Apache2:为什么我会收到 403 Forbidden 错误?

  • 0

这几天我一直在搞砸:(

为什么我在 example.com/contact 上收到 403 Forbidden 错误?

这是文件/文件夹权限、Apache 用户、虚拟主机还是 Python 问题?

我正在尝试在 /contact 上运行 Django 应用程序,但第一个问题是 403 错误。

  • 我正在运行 Ubuntu 20.04.3 LTS
  • Apache 2.4.41 已安装并正在运行
  • 安装了 Python 3.8 和 Django
  • libapache2-mod-wsgi-py3 已安装并启用
  • apachectl configtest语法OK
  • 所有文件 chown 到www-data:www-data
  • 目录 chmod +x
  • example.com/index.html 有效

/var/log/apache2/access.log是空的

/var/log/apache2/error.log包含:

[mpm_prefork:notice] [pid 69090] AH00163: Apache/2.4.41 (Ubuntu) OpenSSL/1.1.1k mod_wsgi/4.6.8 Python/3.8 已配置——恢复正常操作

[核心:通知] [pid 69090] AH00094:命令行:'/usr/sbin/apache2'

根目录下的 .htaccess 文件有

 RewriteEngine on
 ServerSignature Off
 Options All -Indexes

这是我的 public_html 文件结构:

在此处输入图像描述

/etc/apache2/sites-available/default-ssl.conf:

  <IfModule mod_ssl.c>
    <VirtualHost _default_:443>
        ServerAdmin webmaster@localhost
    
        DocumentRoot /var/www/html
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    
        SSLEngine on
    
        SSLCertificateFile  /etc/ssl/certs/ssl-cert-snakeoil.pem
        SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
    
        <FilesMatch "\.(cgi|shtml|phtml|php)$">
                    SSLOptions +StdEnvVars
        </FilesMatch>
        <Directory /usr/lib/cgi-bin>
                    SSLOptions +StdEnvVars
        </Directory>
    
    
    Alias /static /var/www/html/example.com/public_html/contact/static
    Alias /media /var/www/html/example.com/public_html/contact/media

    <Directory /var/www/html/example.com/public_html/contact/static>
        Require all granted
    </Directory>

    <Directory /var/www/html/example.com/public_html/contact/media>
        Require all granted
    </Directory>

    WSGIScriptAlias /contact/contact /var/www/html/example.com/public_html/contact/contact/wsgi.py

    WSGIDaemonProcess contact python-home=/var/www/html/example.com/public_html/contact/contact

    WSGIProcessGroup contact

    WSGISocketPrefix run/wsgi

    <Directory /var/www/html/example.com/public_html/contact/contact>
        <Files wsgi.py>
            Require all granted
            AllowOverride None
            Allow from all
        </Files>
    </Directory>

        </VirtualHost>
</IfModule>
ubuntu virtualhost python apache-2.4
  • 1 个回答
  • 1189 Views
Martin Hope
Adam Larsson
Asked: 2022-01-27 09:12:09 +0800 CST

apache2的不同配置文件?

  • 0

我对此很陌生,并且在网上阅读了很多,但是什么配置是正确的?

在 apache2 中,有些人在谈论httpd.conf,并将所有配置放在一个文件中。

我的安装对我的每个虚拟站点都有 2 个配置文件,一个用于端口 80,一个用于 443。

当我在 apache 的网站上阅读时,看起来只有一个文件?

我很混乱..

有没有区别,还是针对不同的版本?

ubuntu virtualhost httpd.conf apache-2.4
  • 1 个回答
  • 45 Views
Martin Hope
MartinV
Asked: 2022-01-08 08:52:41 +0800 CST

Apache 2.4:要求(例如全部被拒绝)指令未得到遵守

  • 0

我在 Ubuntu 20.04 上运行 Apache 2.4.41 并且无法在我的 VirtualHost 上获得任何 Require 指令。作为一个最低限度的工作示例,我的 VHost 文件:

<VirtualHost *:80>
        ServerName my.domain.com
        DocumentRoot "/var/www/html/admin"

        <Directory /var/www/html/admin>
               Require all denied
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

旨在阻止所有访问,但日志显示:

[authz_core:debug] [pid 340724] mod_authz_core.c(735): [client ***.***.***.***:59008] AH01625: authorization result of <RequireAny>: granted (directive limited to other methods)

我在 Apache 配置树的其他地方看不到任何对 Require 行为的覆盖。例如,/etc/apache2/apache.conf包含:

<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
</Directory>

我加载的模块是:

Loaded Modules:
 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 access_compat_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 cgi_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 filter_module (shared)
 headers_module (shared)
 mime_module (shared)
 mpm_prefork_module (shared)
 negotiation_module (shared)
 php7_module (shared)
 proxy_module (shared)
 proxy_http_module (shared)
 remoteip_module (shared)
 reqtimeout_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 socache_shmcb_module (shared)
 ssl_module (shared)
 status_module (shared)

apachectl -t并apachectl -S给出标准输出。

有人对我接下来应该去哪里有任何想法吗?

(提醒:Apache 2.4 不是 Apache 2.2 所以希望使用当前的术语)

virtualhost apache-2.4 ubuntu-20.04
  • 1 个回答
  • 190 Views
Martin Hope
user76615
Asked: 2021-12-21 16:31:52 +0800 CST

在 LiteSpeed 中,$VH_ROOT 是在哪里定义的?

  • 0

安装 LiteSpeed 后,试验时的第一个任务通常是设置虚拟主机。

当我们在各种设置下查看仪表板时,我们会遇到一些变量。其中之一是 $VH_ROOT。

如何发现 $VH_ROOT 的值?

另外,更具体地说,可以从终端发现 $VH_ROOT 的值吗?如果是这样,怎么做?

virtualhost litespeed
  • 1 个回答
  • 364 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve