jgugugiug 发表于 2018-11-20 14:11:30

Apache安装+虚拟主机

域名
站点目录
  www.etiantian.org
  /var/html/www
  blog.etiantian.org
  /var/html/blog
  bbs.etiantian.org
  /var/html/bbs
  # rpm -qa httpd
  httpd-2.2.15-47.el6.centos.x86_64
  # rpm -e httpd-2.2.15-47.el6.centos.x86_64
  warning: /etc/httpd/conf/httpd.conf saved as /etc/httpd/conf/httpd.conf.rpmsave
  # rpm -qa httpd
  # ls -sh httpd-2.2.27.tar.gz
  7.2M httpd-2.2.27.tar.gz
  # tar xf httpd-2.2.27.tar.gz
  # cd httpd-2.2.27
  # ls INSTALL README
  INSTALLREADME
  # yum -y install zlib zlib-devel
  # ./configure --prefix=/application/apache2.2.27 --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --with-mpm=worker --enable-rewrite
  # echo $?
  0
  # make
  # make install
  # ln -s /application/apache2.2.27/ /application/apache
  # cd
  # /application/apache/bin/apachectl -t
  httpd: apr_sockaddr_info_get() failed for httpd
  httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
  Syntax OK
  # /application/apache/bin/apachectl start
  httpd: apr_sockaddr_info_get() failed for httpd
  httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
  # lsof -i :80
  COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
  httpd   76147   root    4uIPv677976      0t0TCP *:http (LISTEN)
  httpd   76149 daemon    4uIPv677976      0t0TCP *:http (LISTEN)
  httpd   76150 daemon    4uIPv677976      0t0TCP *:http (LISTEN)
  httpd   76151 daemon    4uIPv677976      0t0TCP *:http (LISTEN)
  # /etc/init.d/iptables stop
  # setenforce 0
  setenforce: SELinux is disabled
  # cd /application/apache/conf/
  # ll
  total 92
  -rw-r--r-- 1 root root 53011 Oct 26 21:17 mime.types
  -rw-r--r-- 1 root root 12958 Oct 26 21:17 magic
  drwxr-xr-x 3 root root4096 Oct 26 21:17 original
  -rw-r--r-- 1 root root 13658 Oct 26 21:17 httpd.conf
  drwxr-xr-x 2 root root4096 Oct 26 21:17 extra
  过滤出生效的配置文件:
  # egrep -v "#|^$" httpd.conf
  ServerRoot "/application/apache2.2.27"
  Listen 80
  
  
  User daemon
  Group daemon
  
  
  ServerAdmin you@example.com
  DocumentRoot "/application/apache2.2.27/htdocs"
  
  Options FollowSymLinks
  AllowOverride None
  Order deny,allow
  Deny from all
  
  
  Options Indexes FollowSymLinks
  AllowOverride None
  Order allow,deny
  Allow from all
  
  
  DirectoryIndex index.html
  
  
  Order allow,deny
  Deny from all
  Satisfy All
  
  ErrorLog "logs/error_log"
  LogLevel warn
  
  LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
  LogFormat "%h %l %u %t \"%r\" %>s %b" common
  
  LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
  
  CustomLog "logs/access_log" common
  
  
  ScriptAlias /cgi-bin/ "/application/apache2.2.27/cgi-bin/"
  
  
  
  
  AllowOverride None
  Options None
  Order allow,deny
  Allow from all
  
  DefaultType text/plain
  
  TypesConfig conf/mime.types
  AddType application/x-compress .Z
  AddType application/x-gzip .gz .tgz
  
  
  SSLRandomSeed startup builtin
  SSLRandomSeed connect builtin
  
  # cd extra/
  # pwd
  /application/apache/conf/extra
  # ls -l
  total 56
  -rw-r--r-- 1 root root2859 Oct 26 21:17 httpd-autoindex.conf
  -rw-r--r-- 1 root root1753 Oct 26 21:17 httpd-dav.conf
  -rw-r--r-- 1 root root2344 Oct 26 21:17 httpd-default.conf
  -rw-r--r-- 1 root root1103 Oct 26 21:17 httpd-info.conf
  -rw-r--r-- 1 root root5078 Oct 26 21:17 httpd-languages.conf
  -rw-r--r-- 1 root root   949 Oct 26 21:17 httpd-manual.conf
  -rw-r--r-- 1 root root3789 Oct 26 21:17 httpd-mpm.conf
  -rw-r--r-- 1 root root2207 Oct 26 21:17 httpd-multilang-errordoc.conf
  -rw-r--r-- 1 root root 11530 Oct 26 21:17 httpd-ssl.conf
  -rw-r--r-- 1 root root   817 Oct 26 21:17 httpd-userdir.conf
  -rw-r--r-- 1 root root1507 Oct 26 21:17 httpd-vhosts.conf
  创建网站根目录
  # mkdir /var/html/{www,blog,bbs} -p
  # tree /var/html/
  /var/html/
  |-- bbs
  |-- blog
  `-- www
  

  3 directories, 0 files
  创建网站首页html
  # touch /var/html/{www,blog,bbs}/index.html
  # tree /var/html/
  /var/html/
  |-- bbs
  |   `-- index.html
  |-- blog
  |   `-- index.html
  `-- www
  `-- index.html
  

  3 directories, 3 files
  # for name in www blog bbs;do echo "http://$name.etiantian.org" >/var/html/$name/index.html;done
  # for name in www blog bbs;do cat /var/html/$name/index.html;done
  http://www.etiantian.org
  http://blog.etiantian.org
  http://bbs.etiantian.org
  # cp httpd-vhosts.conf httpd-vhosts.conf_bak
  修改虚拟主机配置文件
  # vim httpd-vhosts.conf
  #
  # Virtual Hosts
  #
  # If you want to maintain multiple domains/hostnames on your
  # machine you can setup VirtualHost containers for them. Most configurations
  # use only name-based virtual hosts so the server doesn't need to worry about
  # IP addresses. This is indicated by the asterisks in the directives below.
  #
  # Please see the documentation at
  #
  # for further details before you try to setup virtual hosts.
  #
  # You may use the command line option '-S' to verify your virtual host
  # configuration.
  

  #
  # Use name-based virtual hosting.
  #
  NameVirtualHost *:80
  

  #
  # VirtualHost example:
  # Almost any Apache directive may go into a VirtualHost container.
  # The first VirtualHost section is used for all requests that do not
  # match a ServerName or ServerAlias in anyblock.
  #
  
  ServerAdmin 510749025@qq.com
  DocumentRoot "/var/html/www"
  ServerName www.etiantian.org
  ServerAlias etiantian.org
  ErrorLog "logs/www-error.log"
  CustomLog "logs/www-access_log" common
  
  
  ServerAdmin 510749025@qq.com
  DocumentRoot "/var/html/blog"
  ServerName blog.etiantian.org
  ErrorLog "logs/blog-error.log"
  CustomLog "logs/blog-access_log" common
  
  
  ServerAdmin 510749025@qq.com
  DocumentRoot "/var/html/bbs"
  ServerName bbs.etiantian.org
  ErrorLog "logs/bbs-error.log"
  CustomLog "logs/bbs-access_log" common
  
  "httpd-vhosts.conf" 50L, 1503C written
  修改主配置文件:添加下面内容
  # tail -6 ../httpd.conf
  
  Options FollowSymLinks
  AllowOverride None
  Order allow,deny
  Allow from all
  
  语法检查:
  # /application/apache/bin/apachectl -t
  httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
  Syntax OK
  重载服务:
  # /application/apache/bin/apachectl graceful
  httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
  




页: [1]
查看完整版本: Apache安装+虚拟主机