Errore 403 proibito durante il tentativo di accedere al server Web Apache 2.4.7 nel browser


9

Quando accedo al server Web Apache utilizzando localhost dallo stesso PC server Web, viene visualizzata la pagina predefinita Ubuntu di Apache2.

Ma quando accedo al server Web Apache utilizzando 192.168.0.2 , viene visualizzato un errore 403 proibito (vietato Non si dispone dell'autorizzazione per accedere / su questo server).

Dettagli del server Web

  • Ubuntu 14.04 LTS
  • Versione Apache 2.4.7

Comandi di proprietà

www-data sudo adduser ftpuser www-data
sudo chown -R www-data:ftpuser /var/www
sudo chmod -R g+rwX /var/www

In etc / apache2 / apache2.conf di file

ServerName 192.168.0.2

<Directory/>
    AllowOverride All
    Require all granted
</Directory>

In etc / apache2 / port.conf di file

NameVirtualHost *:80
Listen *:80

Host virtuale per un sito Web

<VirtualHost *:80>
    ServerName mysite
    DocumentRoot /var/www/mysite
    <Directory /var/www/mysite>
        Options None FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>    
</VirtualHost>

Quali impostazioni devo fare in quale luogo? Per favore aiuto...


Vorrei eliminare la ServerName 192.168.0.2linea poiché la direttiva ServerName dovrebbe avere il nome come www.server.com e non il numero IP. Penso che questo potrebbe risolvere il problema. Per ServerName dovresti inserire il nome del server se ce l'hai. ServerName consente l'hosting virtuale basato sul nome, che consente di avere più siti Web sullo stesso IP.
nessuno il

@nobody, l'ho già rimosso dal file ma non ha ancora successo.
K Ahir,

Risposte:


8

1. Dovresti configurare il tuo file / etc / hosts in questo modo:

127.0.0.1   localhost
127.0.0.1   test-site
127.0.1.1   my-hostname
# The following lines are desirable for IPv6 capable hosts. etc...

Dov'è test-siteil secondo "localhost". Ed my-hostnameè il "Nome host di sistema" definito in /etc/hostname.


2. È necessario definire e abilitare un host virtuale (VH):

C'è un VH HTTP predefinito. È inserito /etc/apache2/sites-available/. Il nome del file è 000-default.conf. Devi modificarlo (puoi rinominarlo, se vuoi, o creare altri file .conf, basati su di esso) e dopo devi abilitarlo.

È possibile abilitarlo manualmente attraverso la creazione di "link simbolico e soft":

sudo ln -s /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/

Oppure puoi usare lo strumento Apache2 chiamato a2ensite , che fa lo stesso:

sudo a2ensite 000-default.conf

Supponiamo che ci siano 3 host virtuali , SSL abilitato e dominio privato registrato (SOS.info per un esempio):

/etc/apache2/sites-available/http.SOS.info.conf
/etc/apache2/sites-available/https.SOS.info.conf

E uno che è stato creato ai fini di questo argomento:

/etc/apache2/sites-available/http.test-site.conf

Il contenuto dei primi 2 VH è:

$ cat /etc/apache2/sites-available/http.SOS.info.conf

<VirtualHost *:80>    
    ServerName SOS.info
    ServerAlias www.SOS.info
    ServerAdmin admin@SOS.info

    # Redirect Requests to SSL
    Redirect permanent "/" "https://SOS.info/"

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

Questo reindirizza tutte le richieste HTTP a HTTPS.

$ cat /etc/apache2/sites-available/https.SOS.info.conf

<IfModule mod_ssl.c>    
    <VirtualHost _default_:443>    
        ServerName SOS.info
        ServerAlias www.SOS.info
        ServerAdmin admin@SOS.info

        DocumentRoot /var/www/html  

        SSLEngine on    
        SSLCertificateFile /etc/ssl/certs/SOS.info.crt
        SSLCertificateKeyFile /etc/ssl/private/SOS.info.key
        SSLCertificateChainFile /etc/ssl/certs/SOS.info.root-bundle.crt
        #etc..
    </VirtualHost>    
</IfModule>

Questo è HTTPS VH.

Il contenuto di questi due file può essere pubblicato in un unico file, ma in questo caso la loro gestione ( a2ensite/ a2dissite) sarà più difficile.


Il terzo host virtuale è quello creato per i nostri scopi :

$ cat /etc/apache2/sites-available/http.test-site.conf

<VirtualHost *:80>
    ServerName test-site
    ServerAlias test-site.SOS.info

    DocumentRoot /var/www/test-site
    DirectoryIndex index.html

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

    <Directory /var/www/test-site>
        # Allow .htaccess 
        AllowOverride All
        Allow from All
    </Directory>    
</VirtualHost>

3. Con questa configurazione è necessario accedere a:

http://localhost     # pointed to the directory of the mine Domain 
https://localhost    # iin our case: /var/www/html (SOS.info), but you should get an error, because the SSL certificate

http://SOS.info      # which redirects to https://SOS.info
https://SOS.info     # you should have valid SSL certificate

http://www.SOS.info  # which is allied to http://SOS.info and redirects to https://SOS.info
https://www.SOS.info # which is allied to https://SOS.info

Nell'esempio principale dovresti accedere e :

http://test-site           # pointed to the directory /var/www/test-site
http://test-site.SOS.info  # which is allied to http://test-site

Prova ad aprire il sito nel browser web o prova (nel terminale) con i seguenti comandi:

$ curl -L http://test-site/index.html
$ curl -L http://test-site.SOS.info/index.html

Ovviamente, devi avere alcune index.htmlpagine in DocumentRoot :)



Lascerò le prossime note a causa della pedanteria :)


4. È necessario configurare correttamente `/ etc / apache2 / apache2.conf`.

È consigliabile passare un po 'di tempo per migliorare la sicurezza del server. Questi manuali riguardano la configurazione della sicurezza: 1 ° e 2 ° . Qui puoi ottenere il certificato SSL gratuito. Questi siti ti aiuteranno a verificare i tuoi progressi: 1 ° e 2 ° .

Secondo i manuali di sicurezza di cui sopra, il /etc/apache2/apache2.conffile deve essere simile a:

Mutex file:${APACHE_LOCK_DIR} default

PidFile ${APACHE_PID_FILE}

Timeout 60

#KeepAlive Off
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5

HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Include ports.conf

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

<Directory /var/www/>
    Options None FollowSymLinks 
    AllowOverride None
    Require all granted
</Directory>

AccessFileName .htaccess
<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf

# Hide Server type in the http error-pages 
ServerSignature Off
ServerTokens Prod

# Etag allows remote attackers to obtain sensitive information 
FileETag None

# Disable Trace HTTP Request
TraceEnable off

# Set cookie with HttpOnly and Secure flag.
# a2enmod headers
Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure

# Clickjacking Attack
Header always append X-Frame-Options SAMEORIGIN

# CX-XSS Protection
Header set X-XSS-Protection "1; mode=block"

# Disable HTTP 1.0 Protocol
RewriteEngine On
RewriteCond %{THE_REQUEST} !HTTP/1.1$
RewriteRule .* - [F]

# Change the server banner @ ModSecurity 
# Send full server signature so ModSecurity can alter it
ServerTokens Full
# Alter the web server signature sent by Apache
<IfModule security2_module>
    SecServerSignature "Apache 1.3.26"
</IfModule>
Header set Server "Apache 1.3.26"
Header unset X-Powered-By

# Hde TCP Timestamp
#   gksu gedit /etc/sysctl.conf
#   >> net.ipv4.tcp_timestamps = 0
# Test: sudo hping3 SOS.info -p 443 -S --tcp-timestamp -c 1

# Disable -SSLv2 -SSLv3 and weak Ciphers
SSLProtocol all -SSLv2 -SSLv3
SSLHonorCipherOrder on
SSLCipherSuite "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA EECDH EDH+aRSA !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !RC4"

5. Configurare il firewall.

Per consentire / negare l'accesso esterno al server Web è possibile utilizzare UFW (Firewall semplice):

sudo ufw allow http
sudo ufw allow https

Per consentire solo l' tcpuso del protocollo:

sudo ufw allow http/tcp
sudo ufw allow https/tcp

È possibile utilizzare e il numero di porta direttamente:

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

Nel caso in cui sia possibile ricaricare la "tabella delle regole":

sudo ufw reload

Puoi usare l'interfaccia GUI di UFW, chiamata gufw .

sudo apt update
sudo apt install gufw
gufw &

Scegli il Officeprofilo. Sarà set: Status:ON, Incoming:Denye Outgoing:Allowe aggiungi le regole.


6. Se si dispone di un router, non dimenticare di inoltrare alcune porte:

Se si dispone di un router e si desidera che il proprio server Web sia accessibile da Internet , non dimenticare di aggiungere un port forwarding. Qualcosa di simile a questo .


Il file 000-default.conf è già presente nella cartella / etc / apache2 / sites-enabled /. Quindi dovrei ancora abilitarlo usando il comando sopra? Per favore mi faccia sapere.
K Ahir,

Se è già lì non è necessario utilizzarli.
pa4080,

Forse troverai i motivi di questo errore in /var/log/apache2/error.log.
pa4080,

Ho aggiornato il mio commento.
pa4080,

Ricezione di questo messaggio di errore ... [Venerdì 12 agosto 17: 18: 37.224182 2016] [mpm_prefork: avviso] [pid 4335] AH00169: catturato SIGTERM, chiusura [Venerdì 12 agosto 17: 18: 40.679317 2016] [mpm_prefork: avviso] [pid 4571] AH00163: Apache / 2.4.7 (Ubuntu) configurato PHP / 5.5.9-1ubuntu4.19 - ripresa delle normali operazioni [venerdì 12 agosto 17: 18: 40.679382 2016] [core: avviso] [pid 4571] AH00094 : Riga di comando: '/ usr / sbin / apache2'
K Ahir,

3

Modifica la proprietà della directory in cui stai servendo i tuoi file utilizzando il comando:

sudo chown -R www-data:www:data <directory_where_you_serve_files_from>

Mi dispiace non menzionare nella mia domanda ma ho già assegnato la proprietà a un gruppo specifico e all'utente per la cartella / var / www.
K Ahir,

0

Dovrei collegarti a questa risposta per risolvere il mio problema.

Prima di tutto, aggiungi le autorizzazioni alla cartella:

sudo chmod -R 775 /var/www

Quindi aggiungi questo testo:

<Directory /var/www/html>
  AllowOverride All
</Directory>

Alla fine di questo file:

/etc/apache2/sites-available/000-default.conf
Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.