当我从同一台Web服务器PC使用本地主机访问Apache Web服务器时,它将显示Apache2 Ubuntu默认页面。
但是,当我使用192.168.0.2访问Apache Web服务器时,它显示403 Forbidden错误(Forbidden您无权访问此服务器上的/)。
Web服务器详细信息
所有权命令
www-data sudo adduser ftpuser www-data
sudo chown -R www-data:ftpuser /var/www
sudo chmod -R g+rwX /var/www
在etc / apache2 / apache2.conf文件中
ServerName 192.168.0.2
<Directory/>
AllowOverride All
Require all granted
</Directory>
在etc / apache2 / port.conf文件中
NameVirtualHost *:80
Listen *:80
一个网站的虚拟主机
<VirtualHost *:80>
ServerName mysite
DocumentRoot /var/www/mysite
<Directory /var/www/mysite>
Options None FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
我需要在什么地方进行哪些设置?请帮忙...
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...
test-site
第二个“本地主机”在哪里。并且my-hostname
是中定义的“系统主机名” /etc/hostname
。
有一个默认的HTTP VH。它放在中/etc/apache2/sites-available/
。档案名称为000-default.conf
。您必须对其进行编辑(如果需要,可以对其进行重命名,或者基于该文件创建其他一些.conf文件),然后必须启用它。
您可以通过创建“软符号链接”来手动启用它:
sudo ln -s /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/
或者,您可以使用称为a2ensite的Apache2工具,该工具具有相同的功能:
sudo a2ensite 000-default.conf
假设有3个虚拟主机,启用的SSL和注册的私有域(例如SOS.info):
/etc/apache2/sites-available/http.SOS.info.conf
/etc/apache2/sites-available/https.SOS.info.conf
出于本主题的目的而创建的一个:
/etc/apache2/sites-available/http.test-site.conf
前两个VH的内容是:
$ cat /etc/apache2/sites-available/
http.SOS.info.conf
<VirtualHost *:80>
ServerName SOS.info
ServerAlias www.SOS.info
ServerAdmin [email protected]
# 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>
这将所有HTTP请求重定向到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 [email protected]
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>
这是HTTPS VH。
这两个文件的内容可以发布到一个文件中,但是在这种情况下,它们的管理(a2ensite
/ a2dissite
)将更加困难。
第三个虚拟主机就是为了我们的目的而创建的:
$ 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>
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
在主要示例中,您应该访问和:
http://test-site # pointed to the directory /var/www/test-site
http://test-site.SOS.info # which is allied to http://test-site
尝试在Web浏览器中打开网站,或尝试(在终端中)使用以下命令:
$ curl -L http://test-site/index.html
$ curl -L http://test-site.SOS.info/index.html
当然,您需要index.html
在其DocumentRoot中包含一些页面:)
由于脚手架的原因,我将留下下一个音符:)
最好花一些时间来提高服务器的安全性。这些手册是关于安全性配置的:1st和2nd。您可以在这里获得免费的SSL证书。这些站点将帮助您检查进度:1st和2nd。
根据以上安全手册/etc/apache2/apache2.conf
文件必须如下所示:
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"
要允许/拒绝外部访问Web服务器,可以使用UFW(非复杂防火墙):
sudo ufw allow http
sudo ufw allow https
要仅允许使用tcp
协议:
sudo ufw allow http/tcp
sudo ufw allow https/tcp
您可以直接使用和端口号:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
以防万一您可以重新加载“规则表”:
sudo ufw reload
您可以使用UFW的GUI界面,称为gufw。
sudo apt update
sudo apt install gufw
gufw &
选择Office
配置文件。它将为:Status:ON
,Incoming:Deny
并Outgoing:Allow
添加你的规则。
如果您有路由器,并且希望可以从Internet访问Web服务器,请不要忘记添加一些端口转发。像这样的东西。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句