修改监听端口为888,使用localhost:888访问检查是否成功。
配置文件位于:
/etc/apache2/ports.conf
文件内容为:
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf
Listen 888
Listen 443
Listen 443
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
修改listen为888
为自己的apache服务器配置个域名,修改hosts和host.conf文件,使之起作用,用浏览器访问域名查看是否成功。
配置文件位于:
/etc/hosts
/etc/host.conf
使用ipconfig查看ip地址,然后在hosts文件中加上第一行(如下):
192.168.23.130 www.666.com
127.0.0.1 localhost
127.0.1.1 ubuntu
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
在host.conf文件中确保order hosts,bind 顺序正确(先查找hosts文件再访问DNS服务器):
# The "order" line is only used by old versions of the C library.
order hosts,bind
multi on
在documentRoot目录下创建一个ref目录,在ref目录下创建img目录,从网上下载两个logo图片文件。
(1)为该目录创建别名Alias /image /var/www/html/ref/img,
(2)在主页上使用引入显示logo图片文件。
(3)在/var/www/html/下为img目录创建一个链接imgs,使用这个链接访问该目录。
(1)
- 创建目录/var/www/html/ref/img,添加一些LOGO图片
- 修改配置文件,配置文件位于:
/etc/apache2/mods-available/alias.conf
修改配置文件如下(添加最后一行):
# Aliases: Add here as many aliases as you need (with no limit). The format is
# Alias fakename realname
#
# Note that if you include a trailing / on fakename then the server will
# require it to be present in the URL. So "/icons" isn't aliased in this
# example, only "/icons/". If the fakename is slash-terminated, then the
# realname must also be slash terminated, and if the fakename omits the
# trailing slash, the realname must also omit it.
#
# We include the /icons/ alias for FancyIndexed directory listings. If
# you do not use FancyIndexing, you may comment this out.
Alias /icons/ "/usr/share/apache2/icons/"
Options FollowSymlinks
AllowOverride None
Require all granted
Alias /image /var/www/html/ref/img
(2)
1.在/var/www/html目录下编写index.html如下:
- 浏览器中访问 www.666.com:888 即可
(3)
- 在/var/www/html目录下,建立软链接如下:
ln -s ./ref/img imgs
- 在浏览器中访问 www.666.com:888/imgs 即可
创建一个目录doc,目录下复制一些文件,
(1)要求该目录不能indexes列表显示
(2)要求该目录必须登录才能访问
(1)
1.在/var/www/html目录下新建目录doc,并在目录中放入一下文件
2.配置文件目录为:
/etc/apache2/sites-available/000-default.conf
修改配置文件(注意由于前面将listen修改为888,VirtualHost需修改为888),并加入Directory内容(options中无Indexes),注意DocumentRoot修改:
# 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 www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# 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
Options MultiViews
AllowOverride AuthConfig
Order allow,deny
Allow from all
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
(2)
- 上述配置文件中加回Indexes
- 在doc目录新建.htaccess以及.htpasswd
sudo vim .htaccess
AuthName "login first" #提示语
AuthType Basic
AuthUserFile /var/www/html/doc/.htpasswd #用户文件路径
Require valid-user #使用 Require valid-user表示用户文件里的所用户用都可以登录。Require user tom表示只要刚才创建文件里的tom用户可以登录。
新建用户文件.htpasswd
htpasswd -c /var/www/html/doc/.htpasswd jenny
创建两个虚拟主机,域名自己选择,创建相应的目录,修改相应的配置,为不同的站点创建不同的主页,例如使用前面下载的logo,用浏览器访问两个站点看到不同的主页。
- 在目录:
/etc/apache2/sites-enabled
修改配置文件:
000-default.conf
# 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 www.666.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# 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
Options Indexes MultiViews
AllowOverride AuthConfig
Order allow,deny
Allow from all
# 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 www.233.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/auth
# 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
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
若为服务器则可直接访问,测试环境则需修改配置文件:
/etc/hosts
修改为:
192.168.23.130 www.666.com
192.168.23.130 www.233.com
127.0.0.1 localhost
127.0.1.1 ubuntu
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters