apache多端口虚拟主机配置方法,学习中遇到的坑

Linux基础教程学习笔记37——Apache配置与治本

1、展开httpd.conf,查找Listen:80,在底下一行参与Listen:8080;
2、查找#Include conf/extra/httpd-vhosts.conf,将此行前边的#去掉;
3、展开httpd.conf文件目录上面包车型客车extra文件夹下边的httpd-vhosts.conf文件;
4、查找NameVirtualHost *:80,在下边一行扩展NameVirtualHost *:8080;
5、复制httpd-vhosts.conf文件最上边包车型客车如下代码,并且在上边粘贴一份:

Apache重启时报警:

AH00112: Warning: DocumentRoot
[/usr/local/apache/docs/dummy-host.example.com] does not exist

AH00112: Warning: DocumentRoot
[/usr/local/apache/docs/dummy-host2.example.com] does not exist

难题原因:

Apache在陈设虚拟主机时会在安插文件中(httpd.conf)开启虚拟主机的布置文件;

将“ #Include /etc/httpd/extra/httpd-vhosts.conf ”前面的“#”去掉;

而“httpd-vhosts.conf ”中会有四个布局虚拟主机的事例:

<VirtualHost *:80>
  ServerAdmin
webmaster@dummy-host.example.com
   DocumentRoot “/usr/local/apache/docs/dummy-host.example.com”
   ServerName dummy-host.example.com
   ServerAlias
www.dummy-host.example.com
   ErrorLog “logs/dummy-host.example.com-error_log”
   CustomLog “logs/dummy-host.example.com-access_log” common
</VirtualHost>

<VirtualHost *:80>
   ServerAdmin
webmaster@dummy-host2.example.com
   DocumentRoot “/usr/local/apache/docs/dummy-host2.example.com”
   ServerName dummy-host2.example.com
   ErrorLog “logs/dummy-host2.example.com-error_log”
   CustomLog “logs/dummy-host2.example.com-access_log” common
</VirtualHost>

那样Apache在运营时就能去寻找以上三个不设有的文书夹,就能报错。

减轻格局:
格局二:将“httpd-vhosts.conf ”中的例子注释掉;

#<VirtualHost *:80>
  #    ServerAdmin
webmaster@dummy-host2.example.com
  #    DocumentRoot
“/usr/local/apache/docs/dummy-host2.example.com”
  #    ServerName dummy-host2.example.com
  #   ErrorLog “logs/dummy-host2.example.com-error_log”
  #    CustomLog “logs/dummy-host2.example.com-access_log”
common
  #</VirtualHost>

一、Httpd.conf配置文件首要参数

复制代码 代码如下:

问题

$link = mysqli_connect('192.168.0.102','root','123456','my_database');

把192.168.0.102换成127.0.0.1就OK
错误代码是1130,E中华VRO奥迪Q3 1130: Host xxx.xxx.xxx.xxx is not allowed to
connect to this MySQL server 是无能为力给长途连接的用户权限难点

ServerRoot:

<VirtualHost *:80> 
        ServerAdmin webmaster@dummy-host.abc.com 
        DocumentRoot “G:\PHP” 
        ServerName dummy-host.abc.com 
        ServerAlias www.dummy-host.abc.ccom 
        ErrorLog “logs/dummy-host.abc.com-error.log” 
        CustomLog “logs/dummy-host.abc.com-access.log” common 
    </VirtualHost> 

减轻格局

在mysql命令行输入
GRANT ALL PRIVILEGES ON *.* TO ‘数据库用户名’@’%’ IDENTIFIED BY
‘数据库密码’ WITH GRANT OPTION;
看到Query OK, 0 rows affected, 1 warning (0.01 sec) 表示OK了

Listen:增加除80之外的监听端口,如808,须要进入selinux的上下文,
[root@linuxidc ~]# semanage port -a -t http_port_t -p tcp 808

    <VirtualHost *:80> 
        ServerAdmin webmaster@dummy-host2.abc.com 
        DocumentRoot “G:\PHP” 
        ServerName dummy-host2.abc.com 
        ErrorLog “logs/dummy-host2.abc.com-error.log” 
        CustomLog “logs/dummy-host2.abc.com-access.log” common 
    </VirtualHost>

问题

Yii2 Gii
http://localhost/blogDemo2/backend/web/index.php?r=gii没问题
http://192.168.0.102/blogDemo2/backend/web/index.php?r=gii就报错
Forbidden code 403 You are not allowed to access this page

Include:加载的模块

6、将方面代码修改为:

消除办法

在main.php增加

'modules' => [
        'gii' => [
            'class' => 'yii\gii\Module',
            'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.102'],

        ],
    ],

[root@linuxidc ~]# httpd -M 查看加载的模块

复制代码 代码如下:

    ServerName:设置站点名,标识不相同的站点;
       
    DocumentRoot:站点主目录

<VirtualHost *:8080> 
        ServerAdmin webmaster@dummy-host.abc.com 
        DocumentRoot “G:\PHP\abc” 
        ServerName dummy-host.abc.com 
        ServerAlias www.dummy-host.abc.ccom 
        ErrorLog “logs/dummy-host.abc.com-error.log” 
        CustomLog “logs/dummy-host.abc.com-access.log” common 
    </VirtualHost> 

    Directory:目录

    <VirtualHost *:8080> 
        ServerAdmin webmaster@dummy-host2.abc.com 
        DocumentRoot “G:\PHP\abc” 
        ServerName dummy-host2.abc.com 
        ErrorLog “logs/dummy-host2.abc.com-error.log” 
        CustomLog “logs/dummy-host2.abc.com-access.log” common 
    </VirtualHost>

 <Directory “/var/www/html/iso”>
    Options Indexes FollowSymLinks
—-Index指index.html不设有,则列出国访问问财富,FollowSymLinks是还是不是允许软链接待上访问;
    AllowOverride None :是还是不是允许.htaccess文件的故事情节覆盖httpd.conf
    Allow open access:
    Require all granted
    或者Require all denied
        Require ip 192.168.1.10
        Require local
</Directory>

7、保存并重启apache。

 
[root@linuxidc test]# htpasswd -mc .htpasswd tom

备注:
1、以上代码首纵然修改了端口和目录,80端口对应的目录为G:\PHP,8080端口对应的目录为G:\PHP\abc;
2、新扩充的端口对应的目录必须在Apache目录上边;
3、打开

  .htaccess
  1 AuthName “test”
  2 AuthType Basic
  3 AuthUserFile /etc/httpd/conf/.htpasswd
  4 require user
RedHat

下边是有的补充材质:
在大家想 配置多少个虚拟机主机的时候 而且又想端口区别等的图景下 小编在网络找了非常的多 都以聊天了…前几日早上笔者就总计了一深夜 终于把 多少个端口的 apache
配置消除了./

 <IfModule dir_module>
    DirectoryIndex index.html
 </IfModule>

先是在http.conf 上边加个Include /etc/httpd/conf/51buyhost.conf 那句话
等会就领悟了..呵呵

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图