• 网站建设部署与发布--笔记2-部署Apache


    网站部署(Linux)

    部署Apache

    • 操作系统:CentOS 7.2

    1.首先连接云服务器,清楚系统垃圾。

    $ yum clean all

    Loaded plugins: fastestmirror
    Cleaning repos: base epel extras updates
    Cleaning up everything
    Cleaning up list of fastest mirrors

    2.执行系统更新。

    $ yum -y update

    3.安装Apache

    $ yum -y install httpd

    设置Apache开机自启

    $ systemctl enable httpd.service

    启动Apache

    $ systemctl start httpd.service

    打开浏览器,访问云主机的IP地址则可看到Apache测试页面

    接下来配置虚拟主机,一般情况下,我们对于Apache的使用都是通过不同的虚拟主机来使用,并不会在一个服务器上只部署一个网站。

     

    下述命令中rainyii.club是笔者自己的服务器域名,读者更改为自己喜欢的名字也可以。

    4.修改Apache的配置文件

    创建对应的目录,这里我们沿袭Apache的习惯,将我们的文件放在/var/www目录下

    $ mkdir -p /var/www/rainyii.club/public_html

    稍后会将文件放在该目录中。

    修改权限及配置文件

    $ chown -R apache:apache /var/www/rainyii.club/public_html
    $ chmod -R 755 /var/www

    创建网站的首页文件(请读者自行编写首页代码)

    $ vim /var/www/rainyii.club/public_html/index.html

    创建Apache的配置目录文件夹(两个目录,分别是Apache的配置文件,另一个是所有启用的虚拟主机的配置文件)

    $ mkdir /etc/httpd/sites-available
    $ mkdir /etc/httpd/sites-enabled

     修改Apache的默认配置文件,来取保其可以加载我们所需要修改的文件

    $ vim /etc/httpd/conf/httpd.conf

    在文件末尾加入一行代码

    IncludeOptional sites-enabled/*.conf

    创建虚拟主机的配置文件

    $ vim /etc/httpd/sites-available/rainyii.club.conf

    粘贴对应的代码

    <VirtualHost *:80>
        
        ServerName rainyii.club
        DocumentRoot /var/www/rainyii.club/public_btml
        ErrorLog /var/www/rainyii.club/error.log
        CustomLog /var/www/rainyii.club/requests.log combined
    </VirtualHost>

    使用软链接,链接到sites-enabled文件夹

    $ ln -s /etc/httpd/sites-available/rainyii.club.conf /etc/httpd/sites-enabled/rainyii.club.conf

    检验生成的软链接是否正常

    $ cat /etc/httpd/sites-enabled/rainyii.club.conf
    <VirtualHost *:80>
        
        ServerName rainyii.club
        DocumentRoot /var/www/rainyii.club/public_btml
        ErrorLog /var/www/rainyii.club/error.log
        CustomLog /var/www/rainyii.club/requests.log combined
    </VirtualHost>

    检查DocumentRoot是否路径一致

    $ cd /var/www/rainyii.club/public_html
    $ ls
    index.html

    5.重启Apache

    $ apachectl restart

    如果任何返回则没有问题,接下来就可以在浏览器中访问了。

    附:httpd服务程序的主要配置文件及存放位置

    配置文件的名称  存放位置
    服务目录 /etc/httpd
    主配置文件 /etc/httpd/conf/httpd.conf
    网站数据目录 /var/www/html
    访问日志 /var/log/httpd/access_log
    错误日志 /var/log/httpd/error_log
  • 相关阅读:
    mysql 优化
    二叉查找树(BST)、红黑树、B-树、B+树
    HashMap,ConcurrentHashMap 原理分析
    2019_京东JAVA实习生招聘机试第一题
    2019年今日头条机试_JAVA后台岗_第二题
    2019年今日头条机试_JAVA后台岗_第一题
    C++_pthread read-write lock_读写锁_visual studio 2015下配置
    Winsock2_WSADATA
    leetcode_1011. Capacity To Ship Packages Within D Days_binary search二分
    leetcode_684. Redundant Connection
  • 原文地址:https://www.cnblogs.com/LMIx/p/10711783.html
Copyright © 2020-2023  润新知