AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / server / Perguntas / 950327
Accepted
Tobia
Tobia
Asked: 2019-01-23 23:57:17 +0800 CST2019-01-23 23:57:17 +0800 CST 2019-01-23 23:57:17 +0800 CST

Configuração do Apache: como limitar a solicitação sem nome de host a algumas páginas?

  • 772

Eu tenho uma configuração de virtualhost do meu servidor Apache:

<VirtualHost *:80>
    DocumentRoot "/app/www"
    ServerName myhostname
    <Directory "/app/www">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Eu quero permitir o acesso apenas solicitações com myhostnameo nome do host. Mas eu quero negar todas as outras solicitações feitas por hostname ou server-ip:

http://myhostiname/ ALLOW
http://1.2.3.4/ (this is one of the server ip addresses) DENY

Minha configuração de virtualhost funciona conforme o esperado.

Agora eu tenho que editar a configuração para permitir que o usuário acesse um determinado caminho por ip porque um cliente não pode resolver o nome do host local.

Isto é um exemplo:

http://myhostiname ALLOW
http://1.2.3.4/ DENY
http://1.2.3.4/any/path DENY
http://1.2.3.4/allowed/path ALLOW
http://1.2.3.4/allowed/path/subpath ALLOW

Eu tentei o <Location>elemento em um novo virtualhost:

<VirtualHost 0.0.0.0:80>
    DocumentRoot "/app/www"
    <Directory "/app/www">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    <Location "/">
      AllowOverride None
      Order Deny,Allow
      Deny from all
    </Location>
    <Location "^/allowed">
      Allow from all
    </Location> 
</VirtualHost>

Mas isso nega tudo, exceto as solicitações de nome de host. O que estou perdendo?

apache-2.4
  • 1 1 respostas
  • 306 Views

1 respostas

  • Voted
  1. Best Answer
    Freddy
    2019-01-24T07:38:39+08:002019-01-24T07:38:39+08:00

    Eu dividiria sua configuração de vhost em dois ou mais vhosts. É possível fazer tudo em um vhost, mas acho as configurações "separadas" mais fáceis de ler e registrar.

    <VirtualHost *:80>
        # default match for port 80
        # matches domain set by ServerName (and possibly other domains unless specified in other vhosts)
        ServerName myhostname
        DocumentRoot "/app/www"
    
        <Location "/">
            # copied from your example. if not needed, you can remove this <Location/>-block.
            Options Indexes FollowSymLinks
            AllowOverride All
        </Directory>
    
        ErrorLog ${APACHE_LOG_DIR}/error-myhostname.log
        CustomLog ${APACHE_LOG_DIR}/access-myhostname.log combined
    </VirtualHost>
    
    <VirtualHost 1.2.3.4:80>
        # matches all requests to ip address and port
        DocumentRoot "/app/www"
    
        # initially: all requests forbidden
        <Location "/">
            # Options and AllowOverride copied from first vhost. remove if not needed.
            Options Indexes FollowSymLinks
            AllowOverride All
    
            Require all denied
        </Location>
    
        # allow access to everything below "/allowed/path/"
        <Location "/allowed/path/">
            Require all granted
        </Location>
    
        # use separate logfile
        ErrorLog ${APACHE_LOG_DIR}/error-1234.log
        CustomLog ${APACHE_LOG_DIR}/access-1234.log combined
    </VirtualHost>
    
    <VirtualHost *:*>
        # default match
        # fallback for any other ports/ip addresses/domains we might have forgotten/misconfigured
        DocumentRoot "/app/www"
    
        # all requests forbidden
        <Location "/">
            Require all denied
        </Location>
    
        # again, use separate logfile
        ErrorLog ${APACHE_LOG_DIR}/error-default.log
        CustomLog ${APACHE_LOG_DIR}/access-default.log combined
    </VirtualHost>
    
    • 1

relate perguntas

  • Apache2 - SSL não está funcionando

  • Apache <VirtualHost> tag, NÃO redirecione se o IP do cliente = x... como fazer isso?

  • Não consigo habilitar meu site? [fechado]

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Você pode passar usuário/passar para autenticação básica HTTP em parâmetros de URL?

    • 5 respostas
  • Marko Smith

    Ping uma porta específica

    • 18 respostas
  • Marko Smith

    Verifique se a porta está aberta ou fechada em um servidor Linux?

    • 7 respostas
  • Marko Smith

    Como automatizar o login SSH com senha?

    • 10 respostas
  • Marko Smith

    Como posso dizer ao Git para Windows onde encontrar minha chave RSA privada?

    • 30 respostas
  • Marko Smith

    Qual é o nome de usuário/senha de superusuário padrão para postgres após uma nova instalação?

    • 5 respostas
  • Marko Smith

    Qual porta o SFTP usa?

    • 6 respostas
  • Marko Smith

    Linha de comando para listar usuários em um grupo do Windows Active Directory?

    • 9 respostas
  • Marko Smith

    O que é um arquivo Pem e como ele difere de outros formatos de arquivo de chave gerada pelo OpenSSL?

    • 3 respostas
  • Marko Smith

    Como determinar se uma variável bash está vazia?

    • 15 respostas
  • Martin Hope
    Davie Ping uma porta específica 2009-10-09 01:57:50 +0800 CST
  • Martin Hope
    kernel O scp pode copiar diretórios recursivamente? 2011-04-29 20:24:45 +0800 CST
  • Martin Hope
    Robert ssh retorna "Proprietário incorreto ou permissões em ~/.ssh/config" 2011-03-30 10:15:48 +0800 CST
  • Martin Hope
    Eonil Como automatizar o login SSH com senha? 2011-03-02 03:07:12 +0800 CST
  • Martin Hope
    gunwin Como lidar com um servidor comprometido? 2011-01-03 13:31:27 +0800 CST
  • Martin Hope
    Tom Feiner Como posso classificar a saída du -h por tamanho 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich O que é um arquivo Pem e como ele difere de outros formatos de arquivo de chave gerada pelo OpenSSL? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent Como determinar se uma variável bash está vazia? 2009-05-13 09:54:48 +0800 CST

Hot tag

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

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve