当前位置:首页 > CN2资讯 > 正文内容

debian 安装docker 脚本 debian安装httpd

4天前CN2资讯


前言

教程将会讲解如何在debian系统上安装apache2并且在80端口部署多个网站

环境准备

1.本次使用的服务器为debian10
2.睿智头脑和一双手

教程步骤

1.更新apt
这里我就不放设置更新源头的了,网上一搜一大把

#获取apt软件更新 apt-get update

执行效果

root@vps:~# apt-get update Hit:1 http://deb.debian.org/debian buster InRelease Hit:2 http://deb.debian.org/debian buster-updates InRelease Hit:3 http://security.debian.org/debian-security buster/updates InRelease Reading package lists... Done root@vultr:~#

2.安装apache2

apt-get install apache2

执行效果

root@vps:~# apt-get install apache2 Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libbrotli1 libjansson4 liblua5.2-0 ssl-cert Suggested packages: apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser openssl-blacklist The following NEW packages will be installed: apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libbrotli1 libjansson4 liblua5.2-0 ssl-cert 0 upgraded, 12 newly installed, 0 to remove and 0 not upgraded. Need to get 2627 kB of archives. After this operation, 8950 kB of additional disk space will be used. Do you want to continue? [Y/n] Y Get:1 http://deb.debian.org/debian buster/main amd64 libapr1 amd64 1.6.5-1+b1 [102 kB] Get:2 http://deb.debian.org/debian buster/main amd64 libaprutil1 amd64 1.6.1-4 [91.8 kB] Get:3 http://deb.debian.org/debian buster/main amd64 libaprutil1-dbd-sqlite3 amd64 1.6.1-4 [18.7 kB] Get:4 http://deb.debian.org/debian buster/main amd64 libaprutil1-ldap amd64 1.6.1-4 [16.8 kB] Get:5 http://deb.debian.org/debian buster/main amd64 libbrotli1 amd64 1.0.7-2 [270 kB] Get:6 http://deb.debian.org/debian buster/main amd64 libjansson4 amd64 2.12-1 [38.0 kB] Get:7 http://deb.debian.org/debian buster/main amd64 liblua5.2-0 amd64 5.2.4-1.1+b2 [110 kB] Get:8 http://deb.debian.org/debian buster/main amd64 apache2-bin amd64 2.4.38-3+deb10u3 [1307 kB] Get:9 http://deb.debian.org/debian buster/main amd64 apache2-data all 2.4.38-3+deb10u3 [165 kB] Get:10 http://deb.debian.org/debian buster/main amd64 apache2-utils amd64 2.4.38-3+deb10u3 [236 kB] Get:11 http://deb.debian.org/debian buster/main amd64 apache2 amd64 2.4.38-3+deb10u3 [251 kB] Get:12 http://deb.debian.org/debian buster/main amd64 ssl-cert all 1.0.39 [20.8 kB] Fetched 2627 kB in 0s (38.8 MB/s) Preconfiguring packages ... Selecting previously unselected package libapr1:amd64. (Reading database ... 31466 files and directories currently installed.) Preparing to unpack .../00-libapr1_1.6.5-1+b1_amd64.deb ... Unpacking libapr1:amd64 (1.6.5-1+b1) ... Selecting previously unselected package libaprutil1:amd64. Preparing to unpack .../01-libaprutil1_1.6.1-4_amd64.deb ...Unpacking libaprutil1:amd64 (1.6.1-4) ... Selecting previously unselected package libaprutil1-dbd-sqlite3:amd64. Preparing to unpack .../02-libaprutil1-dbd-sqlite3_1.6.1-4_amd64.deb ... Unpacking libaprutil1-dbd-sqlite3:amd64 (1.6.1-4) ... Selecting previously unselected package libaprutil1-ldap:amd64. Preparing to unpack .../03-libaprutil1-ldap_1.6.1-4_amd64.deb ... Unpacking libaprutil1-ldap:amd64 (1.6.1-4) ... Selecting previously unselected package libbrotli1:amd64. Preparing to unpack .../04-libbrotli1_1.0.7-2_amd64.deb ... Unpacking libbrotli1:amd64 (1.0.7-2) ... Selecting previously unselected package libjansson4:amd64. Preparing to unpack .../05-libjansson4_2.12-1_amd64.deb ... Unpacking libjansson4:amd64 (2.12-1) ... Selecting previously unselected package liblua5.2-0:amd64. Preparing to unpack .../06-liblua5.2-0_5.2.4-1.1+b2_amd64.deb ... Unpacking liblua5.2-0:amd64 (5.2.4-1.1+b2) ... Selecting previously unselected package apache2-bin. Preparing to unpack .../07-apache2-bin_2.4.38-3+deb10u3_amd64.deb ... Unpacking apache2-bin (2.4.38-3+deb10u3) ... Selecting previously unselected package apache2-data. Preparing to unpack .../08-apache2-data_2.4.38-3+deb10u3_all.deb ... Unpacking apache2-data (2.4.38-3+deb10u3) ... Selecting previously unselected package apache2-utils. Preparing to unpack .../09-apache2-utils_2.4.38-3+deb10u3_amd64.deb ... Unpacking apache2-utils (2.4.38-3+deb10u3) ... Selecting previously unselected package apache2. Preparing to unpack .../10-apache2_2.4.38-3+deb10u3_amd64.deb ... Unpacking apache2 (2.4.38-3+deb10u3) ... Selecting previously unselected package ssl-cert. Preparing to unpack .../11-ssl-cert_1.0.39_all.deb ... Unpacking ssl-cert (1.0.39) ... Setting up libbrotli1:amd64 (1.0.7-2) ... Setting up libapr1:amd64 (1.6.5-1+b1) ... Setting up libjansson4:amd64 (2.12-1) ... Setting up ssl-cert (1.0.39) ... Setting up liblua5.2-0:amd64 (5.2.4-1.1+b2) ... Setting up apache2-data (2.4.38-3+deb10u3) ... Setting up libaprutil1:amd64 (1.6.1-4) ... Setting up libaprutil1-ldap:amd64 (1.6.1-4) ... Setting up libaprutil1-dbd-sqlite3:amd64 (1.6.1-4) ... Setting up apache2-utils (2.4.38-3+deb10u3) ... Setting up apache2-bin (2.4.38-3+deb10u3) ... Setting up apache2 (2.4.38-3+deb10u3) ... Enabling module mpm_event. Enabling module authz_core. Enabling module authz_host. Enabling module authn_core. Enabling module auth_basic. Enabling module access_compat. Enabling module authn_file. Enabling module authz_user. Enabling module alias. Enabling module dir. Enabling module autoindex. Enabling module env. Enabling module mime. Enabling module negotiation. Enabling module setenvif. Enabling module filter. Enabling module deflate. Enabling module status. Enabling module reqtimeout. Enabling conf charset. Enabling conf localized-error-pages. Enabling conf other-vhosts-access-log. Enabling conf security. Enabling conf serve-cgi-bin. Enabling site 000-default. Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /lib/systemd/system/apache2.service. Created symlink /etc/systemd/system/multi-user.target.wants/apache-htcacheclean.service → /lib/systemd/system/apache-htcacheclean.service. Processing triggers for systemd (241-7~deb10u2) ... Processing triggers for man-db (2.8.5-2) ... Processing triggers for libc-bin (2.28-10) ... root@vps:~#

3.开启伪静态功能并创建网站配置文件
开启伪静态功能并创建网站1的配置文件

a2enmod rewrite touch /etc/apache2/sites-available/www.oneweb.com.conf

执行过程

root@vps:~# a2enmod rewrite Enabling module rewrite. To activate the new configuration, you need to run: systemctl restart apache2 root@vps:~# systemctl restart apache2 root@vps:~# touch /etc/apache2/sites-available/www.oneweb.com.conf root@vps:~#

创建网站2的配置文件

touch /etc/apache2/sites-available/www.twoweb.com.conf

执行过程

root@vps:~# touch /etc/apache2/sites-available/www.twoweb.com.conf root@vps:~#

4.修改网站的配置文件
编辑网站1的配置文件

vim /etc/apache2/sites-available/www.oneweb.com.conf

写入的网站1的配置如下:

#Listen 80 <VirtualHost *:80> ServerAdmin [email protected] ServerName www.oneweb.com ServerAlias www.oneweb.com DocumentRoot "/var/www/www.oneweb.com/html" ErrorLog "/var/www/www.oneweb.com/log/error.log" Customlog "/var/www/www.oneweb.com/log/access.log" combined ###设置网页认证(可选)### #<Directory /var/www/www.oneweb.com/html/> #AllowOverride All #Options All #AuthType Basic #AuthName "By Invitation Only" ##生成密码文件的shell命令是:htpasswd -c /var/www/oneweb.com/passwd.db test #AuthUserFile /var/www/oneweb.com/passwd.db #Require user test #</Directory> </VirtualHost>

编辑网站2的配置文件

vim /etc/apache2/sites-available/www.twoweb.com.conf

写入的网站2的配置如下:

#Listen 80 <VirtualHost *:80> ServerAdmin [email protected] ServerName www.twoweb.com ServerAlias www.twoweb.com DocumentRoot "/var/www/www.twoweb.com/html" ErrorLog "/var/www/www.twoweb.com/log/error.log" Customlog "/var/www/www.twoweb.com/log/access.log" combined DirectoryIndex index.htm index.html </VirtualHost>

5.创建网页路径
A.创建网站1的路径

#创建网站路径 mkdir /var/www/www.oneweb.com #创建网站1存放网页路径 mkdir /var/www/www.oneweb.com/html #创建网站1存放日志路径 mkdir /var/www/www.oneweb.com/log

执行过程

root@vps:~# mkdir /var/www/www.oneweb.com root@vps:~# mkdir /var/www/www.oneweb.com/html root@vps:~# mkdir /var/www/www.oneweb.com/log

B.创建网站2的路径

#创建网站路径 mkdir /var/www/www.twoweb.com #创建网站1存放网页路径 mkdir /var/www/www.twoweb.com/html #创建网站1存放日志路径 mkdir /var/www/www.twoweb.com/log

执行过程

root@vps:~# mkdir /var/www/www.twoweb.com root@vps:~# mkdir /var/www/www.twoweb.com/html root@vps:~# mkdir /var/www/www.twoweb.com/log

6.配置权限
A.设置网站1的文件夹权限及用户

#设置网站1的路径下的文件夹的权限为755 chmod -R 755 "/var/www/www.oneweb.com" #设置网站1的路径下html的文件夹的用户为www-data chmod www-data -R "/var/www/www.oneweb.com/html" #设置网站1的路径下日志的文件夹的权限为750 chmod 750 /var/www/www.oneweb.com/log

执行过程

root@vps:~# chmod -R 755 "/var/www/www.oneweb.com" root@vps:~# chmod www-data -R "/var/www/www.oneweb.com/html" root@vps:~# chmod 750 /var/www/www.oneweb.com/log

B.设置网站2的文件夹权限及用户

#设置网站2的路径下的文件夹的权限为755 chmod -R 755 "/var/www/www.twoweb.com" #设置网站2的路径下html的文件夹的用户为www-data chmod www-data -R "/var/www/www.twoweb.com/html" #设置网站1的路径下日志的文件夹的权限为750 chmod 750 /var/www/www.twoweb.com/log

执行过程

root@vps:~# chmod -R 755 "/var/www/www.twoweb.com" root@vps:~# chmod www-data -R "/var/www/www.twoweb.com/html" root@vps:~# chmod 750 /var/www/www.twoweb.com/log

7.放入测试页面
A.放入网站1的测试页面

echo "This is www.oneweb.com!" >"/var/www/www.oneweb.com/html/index.html"

执行过程

root@vps:~# echo "This is www.oneweb.com!" >"/var/www/www.oneweb.com/html/index.html"

B.放入网站2的测试页面

echo "This is www.twoweb.com!" >"/var/www/www.twoweb.com/html/index.html"

执行过程

root@vps:~# echo "This is www.oneweb.com!" >"/var/www/www.twoweb.com/html/index.html"

8.关闭默认站点并启动自定义的两个站点

#关闭默认站点 a2dissite 000-default.conf #启动我们创建的站点1 a2ensite www.oneweb.com.conf #启动我们创建的站点2 a2ensite www.twoweb.com.conf

执行过程

root@vps:~# a2dissite 000-default.conf Site 000-default disabled. To activate the new configuration, you need to run: systemctl reload apache2 root@vps:~# a2ensite www.oneweb.com.conf Enabling site www.oneweb.com. To activate the new configuration, you need to run: systemctl reload apache2 root@vps:~# a2ensite www.twoweb.com.conf Enabling site www.twoweb.com. To activate the new configuration, you need to run: systemctl reload apache2

9.重启服务

service apache2 restart

执行过程

root@vps:~# service apache2 restart root@vps:~#

验证

A.打开浏览器查看网站1

www.oneweb.com

B.打开浏览器查看网站1

www.twoweb.com


可以看到都成功访问了,我们成功的在一台服务器上搭建使用同一80端口搭建了两个网站


    你可能想看:

    扫描二维码推送至手机访问。

    版权声明:本文由皇冠云发布,如需转载请注明出处。

    本文链接:https://www.idchg.com/info/19778.html

    分享给朋友:

    “debian 安装docker 脚本 debian安装httpd” 的相关文章

    中国电信CN2线路连接图:连接未来,助力企业腾飞

    在信息技术飞速发展的今天,企业对于网络的需求已经从“可用”提升到了“高效、稳定、安全”的更高层次。而在这个数字化转型的关键时期,中国电信推出的CN2线路连接图正成为众多企业的首选解决方案。本文将带您深入了解中国电信CN2线路连接图的核心优势及其在企业中的广泛应用。一、中国电信CN2线路连接图的定义与...

    选择日本VPS的优势与支持比特币支付的推荐服务商

    当谈到日本VPS时,我总是能想到它在全球互联网环境中的独特地位。日本因其低延迟、高稳定性以及优秀的网络连接,成为了许多希望扩大市场的企业和开发者的首选。特别是面向中国、韩国以及东南亚用户,选择日本VPS可以显著提升服务响应速度,让用户体验更为流畅。 日本的数据中心设施相当先进。这里的技术架构可以说是...

    iHerb优惠码使用指南:最大化你的购物折扣

    在现代生活中,网络购物已经成为很多人日常消费的一部分,尤其是像iHerb这样的电商平台,提供了丰富的天然保健品和生活必需品。对于我们消费者来说,iHerb优惠码就是一个能够让购物更加实惠的绝佳工具。 iHerb优惠码是一种特殊的代码,用户在结账时输入这些代码,就可以享受相应的折扣。无论是新用户还是老...

    VPS商家全攻略:选择适合你的虚拟专用服务器

    VPS商家概述 在数字化时代,VPS(虚拟专用服务器)服务逐渐成为企业和个人用户的重要选择。VPS不仅为用户提供了灵活性,而且在性能、控制权和安全性上都优于传统的共享主机。这使它成为许多需要独立环境来运行网站或应用程序的用户的理想解决方案。 选择VPS的用户通常追求更高的稳定性和可靠性。相比于共享主...

    HudsonValleyHost主机服务测评:性价比与稳定性的完美结合

    HudsonValleyHost是一家成立于2014年的国外老牌主机商,已经在行业内稳扎稳打,逐渐树立了自己的品牌形象。这家公司最初的目标是为用户提供高性价比的主机服务,其中以其纽约的KVM VPS服务备受青睐。在我接触的众多主机服务商中,HudsonValleyHost的存在让我感受到了一种稳定与...

    选择香港机房的优势与服务:最理想的数据中心解决方案

    在当今数字化的时代,香港机房作为亚洲地区的数据中心枢纽,其重要性愈发凸显。随着全球对高效、安全、稳定数据处理需求的上升,香港凭借其优越的地理位置和完善的网络基础设施,已成为众多企业首选的托管与服务器服务地点。以高速网络连接、优质的BGP多线路接入以及高标准的设施著称,香港机房为客户提供了一系列的解决...