Ubuntu 18.04利用Apache部署服务器

Ubuntu 18.04利用Apache部署服务器

目前市面常见的几种部署(web服务器)

Ubuntu版本18.04

Apache 、 Nginx 、IIS

  • Apache
    Apache音译为阿帕奇, 是全世界最受欢迎的web服务器,因其快速、可靠并且可通过简单的API扩充,能将Python\Perl等解释器部署在其上面等优势,受到广泛的关注与使用。
  • Nginx

    Apache的致命缺陷就是在同时处理大量的请求时,显得有些吃力,Ngnix在高并发下nginx 能保持比Apache低资源低消耗高性能
  • IIS

    iis是Internet Information Services的缩写,意为互联网信息服务,是由微软公司提供的基于运行Microsoft Windows的互联网基本服务

Apache2 的安装

Linux版本是Ubuntu 18.04的Linux系统上没有httpd这个服务,其实这一点我们不必惊慌,我们也不必单独装一个httpd服务,此时直接装一个Apache,因为httpd是Apache超文本传输协议(HTTP)服务器的主程序。被设计为一个独立运行的后台进程,它会建立一个处理请求的子进程或线程的池

服务安装

sudo apt install apache2 -y

检查是否安装成功

systemctl status apache2

Apache常用操作代码

开启、关闭和重启Apache服务器

/etc/init.d/apache2 start    //启动Apache服务
/etc/init.d/apache2 stop    //停止Apache服务
/etc/init.d/apache2 restart    //重启Apache服务


测试服务器

  • 打开浏览器,输入http://127.0.0.1/ (这是主机默认的IP地址)。当我们看到下面的页面时变说明Apache2 服务已经成功在我们的服务器上工作了。 上图即为初步安装完成

Apache 修改网站根目录及默认网页

  • 修改根目录
    在 /etc/apache2/sites-available 中修改 000-default.conf 中的DocumentRoot /var/www/ 修改为想要的目录
    比如:DocumentRoot /var/www/html/mainpage
    执行命令:
    vim /etc/apache2/sites-available/000-default.conf

修改000-default.conf中的DocumentRoot /var/www/,如下

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html    // 一般我们默认为这个作为网站的根目录

重启Apache

    sudo apache2ctl -k restart 
  • 修改默认页面
  • 修改/etc/apache2/mods-available/dir.conf中的内容
    执行命令:
vim /etc/apache2/mods-available/dir.conf

此前文件内容为:

<IfModule mod_dir.c>
    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm 
</IfModule>

添加上想要的/wordpress就行啦

<IfModule mod_dir.c>
    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm /wordpress
</IfModule>

实际上在这里添加文件或目录的意思是,用于我们允许http请求访问到/var/www/html下的改文件或目录中的内容的意思:
例如我添加了test这个目录

    <IfModule mod_dir.c>
        DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm /test
    </IfModule>

ps:在再里面添加个名为index.html的文档,写入“Hello World!”,于是我们便可通过IP地址127.0.0.1/test/index.html访问 即可看到网站页面

至此Apache搭建完成

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值