配置apache2使用不同埠或者域名訪問網站

  • 2019 年 11 月 26 日
  • 筆記

兩種方式

第一種:通過不同埠訪問

首先更改/etc/apache2/ports.conf具體如下:

  • # If you just change the port or add more ports here, you will likely also
  • # have to change the VirtualHost statement in
  • # /etc/apache2/sites-enabled/000-default
  • # This is also true if you have upgraded from before 2.2.9-3 (i.e. from
  • # Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
  • # README.Debian.gz
  • #增加三個埠80、8080、82、****為你的IP
  • NameVirtualHost ****:80
  • Listen 80
  • NameVirtualHost ****:8080
  • Listen 8080
  • NameVirtualHost ****:82
  • Listen 82
  • <IfModule mod_ssl.c>
  •     # If you add NameVirtualHost *:443 here, you will also have to change
  •     # the VirtualHost statement in /etc/apache2/sites-available/default-ssl
  •     # to <VirtualHost *:443>
  •     # Server Name Indication for SSL named virtual hosts is currently not
  •     # supported by MSIE on Windows XP.
  •     Listen 443
  • </IfModule>
  • <IfModule mod_gnutls.c>
  •     Listen 443
  • </IfModule>

/etc/apache2/sites-available/下的配置文件也要改。如oj(配置文件名)

  • ****為主機IP
  • <VirtualHost ****:82>
  •         ServerAdmin webmaster@localhost
  •         #填寫你所要建立的埠
  •         ServerName *****:82
  •         #網站目錄
  •         DocumentRoot /var/www/html/
  •         <Directory />
  •                 Options FollowSymLinks
  •                 AllowOverride None
  •         </Directory>
  •         <Directory /var/www/>
  •                 Options Indexes FollowSymLinks MultiViews
  •                 AllowOverride All
  •                 Order allow,deny
  •                 allow from all
  •         </Directory>
  •         ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  •         <Directory 「/usr/lib/cgi-bin」>
  •                 AllowOverride None
  •                 Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  •                 Order allow,deny
  •                 Allow from all
  •         </Directory>
  •         ErrorLog ${APACHE_LOG_DIR}/error.log
  •         # Possible values include: debug, info, notice, warn, error, crit,
  •         # alert, emerg.
  •         LogLevel warn
  •         CustomLog ${APACHE_LOG_DIR}/access.log combined
  •     Alias /doc/ 「/usr/share/doc/」
  •     <Directory 「/usr/share/doc/」>
  •         Options Indexes MultiViews FollowSymLinks
  •         AllowOverride None
  •         Order deny,allow
  •         Deny from all
  •         Allow from 127.0.0.0/255.0.0.0 ::1/128
  •     </Directory>
  • </VirtualHost>
  • 建立軟連在/etc/apache2/sitea-enabled/目錄下

敲 ln –s ../sitea-available oj

然後重啟下

  • sudo /etc/init.d/apache2 restart

第二種方法用域名綁定

在/etc/apache2/sites-available/下增加配置文件

如增加oj.conf

  • <VirtualHost *:80>
  •         # The ServerName directive sets the request scheme, hostname and port that
  •         # the server uses to identify itself. This is used when creating
  •         # redirection URLs. In the context of virtual hosts, the ServerName
  •         # specifies what hostname must appear in the request』s Host: header to
  •         # match this virtual host. For the default virtual host (this file) this
  •         # value is not decisive as it is used as a last resort host regardless.
  •         # However, you must set it for any further virtual host explicitly.
  •         #ServerName www.example.comt
  •         #填寫你的域名
  •         Servername www.acmteam.win
  •         ServerAdmin webmaster@localhost
  •         #網站目錄
  •         DocumentRoot /var/www/html/JudgeOnline/
  • #       <Directory /var/www/>
  • #        AllowOverride None
  • #        Order Deny,Allow
  • #        Allow from all
  • #       </Directory>
  •         # Available loglevels: trace8, …, trace1, debug, info, notice, warn,
  •         # error, crit, alert, emerg.
  •         # It is also possible to configure the loglevel for particular
  •         # modules, e.g.
  •         #LogLevel info ssl:warn
  •         ErrorLog ${APACHE_LOG_DIR}/error.log
  •         CustomLog ${APACHE_LOG_DIR}/access.log combined
  •         # For most configuration files from conf-available/, which are
  •         # enabled or disabled at a global level, it is possible to
  •         # include a line for only one particular virtual host. For example the
  •         # following line enables the CGI configuration for this host only
  •         # after it has been globally disabled with 「a2disconf」.
  •         #Include conf-available/serve-cgi-bin.conf
  • </VirtualHost>
  • # vim: syntax=apache ts=4 sw=4 sts=4 sr noet 建立軟連在/etc/apache2/sitea-enabled/目錄下
  • 敲 ln –s ../sitea-available oj

       最後重啟apache

  • sudo /etc/init.d/apache2 restart

原創文章,轉載請註明: 轉載自URl-team

本文鏈接地址: 配置apache2使用不同埠或者域名訪問網站

No related posts.