前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >配置apache2使用不同端口或者域名访问网站

配置apache2使用不同端口或者域名访问网站

作者头像
十四君
发布2019-11-26 18:48:14
4.2K0
发布2019-11-26 18:48:14
举报
文章被收录于专栏:UrlteamUrlteam

两种方式

第一种:通过不同端口访问

首先更改/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.

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-01-032,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 第一种:通过不同端口访问
    • 首先更改/etc/apache2/ports.conf具体如下:
      • /etc/apache2/sites-available/下的配置文件也要改。如oj(配置文件名)
      • 第二种方法用域名绑定
        • 在/etc/apache2/sites-available/下增加配置文件
          • 如增加oj.conf
            •        最后重启apache
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档