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 / user-39133

TRiG's questions

Martin Hope
TRiG
Asked: 2024-09-10 21:36:22 +0800 CST

Na configuração do Apache, os redirecionamentos ou as regras de reescrita têm precedência?

  • 5

Quero que um domínio no Apache exista puramente como um redirecionamento. Para esse fim, crio /etc/apache2/sites-available/redirect.example.info.confo seguinte:

<VirtualHost *:80>
    ServerName redirect.example.info
    ServerAdmin webmaster@localhost
    Redirect / https://example.com/

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

Quando executo certbot --apache, isso é reescrito para:

<VirtualHost *:80>
    ServerName redirect.example.info
    ServerAdmin webmaster@localhost
    Redirect / https://example.com/

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

RewriteEngine on
RewriteCond %{SERVER_NAME} =redirect.example.info
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

E um novo arquivo /etc/apache2/sites-available/redirect.example.info-le-ssl.confé criado:

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName redirect.example.info
    ServerAdmin webmaster@localhost
    Redirect / https://example.com/

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

SSLCertificateFile /etc/letsencrypt/live/ca-webs.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/ca-webs.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

Isso funciona como desejado. Os redirecionamentos são executados http://redirect.example.info→ https://redirect.example.info→ https://example.com. Mas não é óbvio para mim como está funcionando. O arquivo reescrito tem um Redirectcomando e um RewriteRulecomando, e eu pensei que o Redirect(vindo primeiro) teria precedência. Como esse arquivo é realmente avaliado?

apache2
  • 1 respostas
  • 25 Views
Martin Hope
TRiG
Asked: 2019-10-05 02:31:27 +0800 CST

Por que $_SERVER['HTTP_HOST'] às vezes é example.com e às vezes example.com:443?

  • 4

Este é um servidor Ubuntu rodando PHP 7 no Apache, com um site que impõe TLS (usando a porta padrão). No meu entender, https://example.come https://example.com:443são exatamente equivalentes (e, de fato, no meu navegador o número da porta desaparece da barra de endereços quando eu digito). E, no entanto, HTTP_HOST geralmente contém apenas o nome do domínio, mas às vezes também contém o número da porta. Isso pode ser para visitantes de bots (não analisei logs), mas mesmo assim não vejo como. Existe alguma diferença real?

(Isso está causando alguns problemas, pois alguns de nossos logs e filas de trabalho e cache do lado do servidor são separados por HTTP_HOST, portanto, ter o mesmo relatório de site em diferentes hosts é confuso.)

php
  • 1 respostas
  • 5871 Views
Martin Hope
TRiG
Asked: 2017-08-30 05:39:21 +0800 CST

Por que checkrestart não me mostrou que uma reinicialização era necessária?

  • 0

Acabei de instalar alguns atualizados no meu servidor Ubuntu. Alguns deles eram kernel e Linux Headers, então suspeitei que uma reinicialização fosse necessária, mas queria ter certeza. Então, seguindo uma recomendação deste site , instalei o checkrestart.

$ checkrestart
ERROR: This program must be run as root in order to obtain information
about all open file descriptors in the system.

$ sudo !!
sudo checkrestart
Found 0 processes using old versions of upgraded files

Hum. Não é necessário reiniciar? Isso parece estranho.

$ exit
logout
Connection to example.net closed.

$ ssh [email protected] && alert
[email protected]'s password: 
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-92-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

0 packages can be updated.
0 updates are security updates.


*** System restart required ***

Oh. Então é necessário reiniciar? Por que você não disse isso?

$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.3 LTS"

Como posso saber se uma reinicialização é necessária após a instalação das atualizações?

ubuntu
  • 1 respostas
  • 386 Views
Martin Hope
TRiG
Asked: 2016-11-23 09:53:20 +0800 CST

Let's Encrypt redirecionar automaticamente para HTTPS não está funcionando

  • 2

Configurei o Let's Encrypt em meu pequeno servidor Ubuntu e estou usando-o em todos os sites que não são IDN. Tem a opção de redirecionar automaticamente sites HTTP para HTTPS. Eu selecionei essa opção.

O daemon Let's Encrypt adicionou três linhas a cada domínio conf e criou um novo domínio-le-ssl.conf para cada domínio.

Aqui está timothy.green.name.conf:

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.

    ServerName timothy.green.name
    ServerAdmin [email protected]
    DocumentRoot /var/www/vhosts/timothy.green.name/web

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

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

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
RewriteEngine on
RewriteCond %{SERVER_NAME} =timothy.green.name
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>

Eu criei este arquivo, mas o daemon Let's Encrypt adicionou as regras de reescrita no final. Ele também criou o novo arquivo timothy.green.name-le-ssl.conf, que tem a seguinte redação:

<IfModule mod_ssl.c>
<VirtualHost *:443>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.

    ServerName timothy.green.name
    ServerAdmin [email protected]
    DocumentRoot /var/www/vhosts/timothy.green.name/web

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

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

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
RewriteEngine on
RewriteCond %{SERVER_NAME} =timothy.green.name
# Some rewrite rules in this file were were disabled on your HTTPS site,
# because they have the potential to create redirection loops.
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
SSLCertificateFile /etc/letsencrypt/live/myh2g2.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/myh2g2.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
</IfModule>

Isso tudo parece certo. E mod_rewriteestá no lugar:

$ a2enmod rewrite
Module rewrite already enabled

E ainda, enquanto https://timothy.green.name funciona bem, http://timothy.green.name me dá um site padrão do Apache. O que poderia estar errado aqui? Vou reiterar que não adicionei essas regras de reescrita sozinho: o daemon Let's Encrypt fez isso. Portanto, estou assumindo que a sintaxe está correta.

apache2 lets-encrypt
  • 1 respostas
  • 11854 Views

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