周翔 发表于 2019-2-18 07:27:48

Linux20180528

5月28日任务
11.14/11.15 Apache和PHP结合
11.16/11.17 Apache默认虚拟主机
http://s1.运维网.com/images/20180529/1527577988682900.png
  1. 首先看一下:
http://s1.运维网.com/images/20180529/1527579059865968.png
  这是个警告,虽然并非错误但是可以取消掉。办法就是去定义好 servername
  vim /usr/local/apache2/conf/httpd.conf,将servername前面的#去掉即可
http://s1.运维网.com/images/20180529/1527580606397481.png
http://s1.运维网.com/images/20180529/1527581505447547.png
  2. 增加一行配置

  Require all denied 改成 allowed 这样就可以被访问到了!telnet访问肯定不行,因为80端口尚未打开。看下图,无法用telnet访问
http://s1.运维网.com/images/20180529/1527582732115898.png
  需要修改配置文件 vim /usr/local/apache2/conf/httpd.confrequire all granted
http://s1.运维网.com/images/20180529/1527591960839951.png
  /usr/local/apache2/bin/apachectl -t 用来检查配置文件的语法是否正确
http://s1.运维网.com/images/20180529/1527592159491156.png
  /usr/local/apache2/bin/apachectl graceful 重新加载配置文件 不会影响进程
  3. 增加一行与php相关的配置。 搜AddType 然后增加一行可以让php解析的语句
  AddType application/x-httpd-php .php
http://s1.运维网.com/images/20180529/1527593034260313.png
  4. 在/htodcs下放一个文件,php 文件 看是否加载php。
  但是失败了。
  原因是防火墙的设置忘记设置了,所以没有打开80端口。
  iptables -I INPUT -p tcp --dport 80 -j ACCEPT 临时打开80端口就好了。 http://s1.运维网.com/images/20180529/1527595099521481.png
  注意,同样将php5换成7也可以成立。
  Apache默认虚拟主机
http://s1.运维网.com/images/20180529/1527603479106227.png
  可以理解成在一个httpd服务下运行了多个网站,域名。每个域名对应的是一个虚拟主机。
  有一个httpd配置文件的位置,DocumentRoot定义了网站的根目录的位置。ServerName定义的就是域名。
  首先从windows下来进行理解。
  windows下hosts的地址是 C:\Windows\System32\drivers\etc\hosts
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97   rhino.acme.com          # source server
#       38.25.63.10   x.acme.com            # x client host
# localhost name resolution is handled within DNS itself.
#127.0.0.1       localhost
#::1             localhost  可以在这里面定义一个ip 域名,让域名指向ip

http://s1.运维网.com/images/20180529/1527603874579960.png
  然后访问www.163.com就变成了访问192.168.202.123
http://s1.运维网.com/images/20180529/1527604318184359.png
http://s1.运维网.com/images/20180529/1527604310591610.png
  这样就临时改变了一个域名对应的ip, 这是在DNS未生效的情况下使用
  Linux下的虚拟主机 apache配置文件中 virtual hosts
http://s1.运维网.com/images/20180529/1527604610848526.png
  将这个注释取消后,就可以去到一个二级文件目录对虚拟主机进行定义。

  vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
  每一对成对出现的 VirtualHost标签就代表一个主机的定义。第一个是默认的虚拟主机。
http://s1.运维网.com/images/20180529/1527604873842603.png
  如果虚拟目录生效的话,apache的配置文件里的servername就失效了。
http://s1.运维网.com/images/20180529/1527605755326535.png
  然后在对应的位置创建目录以及index测试文件。
http://s1.运维网.com/images/20180529/1527605972441548.png
  测试虚拟主机
  curl 命令来实现访问虚拟主机
  curl -x192.168.202.123:80 www.goau.com.au
http://s1.运维网.com/images/20180529/1527606392355178.png



页: [1]
查看完整版本: Linux20180528