您的位置:首页 > 运维架构 > Apache

Ubuntu 18.04利用Apache部署服务器

2020-02-02 02:39 1531 查看

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搭建完成

  • 点赞
  • 收藏
  • 分享
  • 文章举报
小史史啊 发布了13 篇原创文章 · 获赞 2 · 访问量 3194 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: