Apache 'Directory Alias' 无法在 vagrant Homestead 中工作
Apache 'Directory Alias' not working in vagrant Homestead
为了在我的本地机器上复制我们的生产服务器,我在 Homestead 的 VirtualHost conf 中创建了一个 'Directory Alias'。但是,不管我从各种 Whosebug 帖子中尝试了多少设置,我总是在浏览器中收到相同的 404 not found 响应。希望有人能帮我解决这个问题?
在 Homestead 中,我将 Nginx 替换为 Apache,并重组了服务器根目录和项目文件的位置,以匹配我们的生产服务器。这是我的 Homestead.yaml 文件:
---
ip: "192.168.10.10"
memory: 2048
cpus: 2
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: /Users/johno/vhosts/homestead.client1.co.uk
to: /srv/www/vhosts/homestead.client1.co.uk
sites:
- map: homestead.client1.co.uk
to: /srv/www/vhosts/homestead.client1.co.uk/public
type: apache
databases:
- project_two
# ports:
# - send: 50000
# to: 5000
# - send: 7777
# to: 777
# protocol: udp
这是我的虚拟主机文件:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName homestead.client1.co.uk
ServerAlias www.homestead.client1.co.uk
DocumentRoot /srv/www/vhosts/homestead.client1.co.uk/public
<Directory /srv/www/vhosts/homestead.client1.co.uk/public>
AllowOverride All
Require all granted
</Directory>
# code added
Alias /project-one /srv/www/vhosts/homestead.client1.co.uk/project-one/public
<Directory "/srv/www/vhosts/homestead.client1.co.uk/project-one/public">
Options None
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
# code added
<IfModule mod_fastcgi.c>
AddHandler php7.3-fcgi .php
Action php7.3-fcgi /php7.3-fcgi
Alias /php7.3-fcgi /usr/lib/cgi-bin/php7.3
FastCgiExternalServer /usr/lib/cgi-bin/php7.3 -socket /var/run/php/php7.3-fpm.sock -pass-header Authorization
</IfModule>
<IfModule !mod_fastcgi.c>
<IfModule mod_proxy_fcgi.c>
<FilesMatch ".+\.ph(ar|p|tml)$">
SetHandler "proxy:unix:/var/run/php/php7.3-fpm.sock|fcgi://localhost"
</FilesMatch>
</IfModule>
</IfModule>
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/homestead.client1.co.uk-error.log
CustomLog ${APACHE_LOG_DIR}/homestead.client1.co.uk-access.log combined
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
我对虚拟主机所做的唯一修改是在 # code added
.
之间添加了代码
我在服务器根目录中放置了一个 index.php
文件,显示 phpinfo();
:
vagrant@homestead:~$ ls -la /srv/www/vhosts/homestead.client1.co.uk/public/
total 4
drwxr-xr-x 1 vagrant vagrant 96 Sep 8 05:14 .
drwxr-xr-x 1 vagrant vagrant 160 Sep 8 05:07 ..
-rw-r--r-- 1 vagrant vagrant 17 Sep 7 05:10 index.php
在浏览器中我可以访问 http://homestead.client1.co.uk/index.php
并成功看到它的输出,所以服务器工作正常。
但是,如果我使用 http://homestead.client1.co.uk/project-one/index.php
请求 'Alias' 目录,我会收到 404 未找到响应。
我可以确认项目文件位于 vhost 别名中指定的位置并且权限设置正确:
vagrant@homestead:~$ ls -la /srv/www/vhosts/homestead.client1.co.uk/project-one/public/
total 28
drwxr-xr-x 1 vagrant vagrant 192 Sep 7 06:41 .
drwxr-xr-x 1 vagrant vagrant 96 Sep 7 06:40 ..
drwxr-xr-x 1 vagrant vagrant 96 Sep 7 06:41 css
drwxr-xr-x 1 vagrant vagrant 480 Sep 7 06:41 images
-rw-r--r-- 1 vagrant vagrant 24679 Sep 7 06:40 index.php
drwxr-xr-x 1 vagrant vagrant 96 Sep 7 06:40 libs
如您所见,'project-one' 不是 laravel 框架,它是一个用于测试目的的简单静态登录页面。
任何帮助解决问题都将非常有用,谢谢。
错误日志是否显示任何内容?
您可以尝试在 project-one 别名下添加 Require All Granted
,如下所示:
Alias /project-one /srv/www/vhosts/homestead.client1.co.uk/project-one/public
<Directory "/srv/www/vhosts/homestead.client1.co.uk/project-one/public">
Options None
AllowOverride All
Order Deny,Allow
Allow from all
Require all granted
</Directory>
为了在我的本地机器上复制我们的生产服务器,我在 Homestead 的 VirtualHost conf 中创建了一个 'Directory Alias'。但是,不管我从各种 Whosebug 帖子中尝试了多少设置,我总是在浏览器中收到相同的 404 not found 响应。希望有人能帮我解决这个问题?
在 Homestead 中,我将 Nginx 替换为 Apache,并重组了服务器根目录和项目文件的位置,以匹配我们的生产服务器。这是我的 Homestead.yaml 文件:
---
ip: "192.168.10.10"
memory: 2048
cpus: 2
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: /Users/johno/vhosts/homestead.client1.co.uk
to: /srv/www/vhosts/homestead.client1.co.uk
sites:
- map: homestead.client1.co.uk
to: /srv/www/vhosts/homestead.client1.co.uk/public
type: apache
databases:
- project_two
# ports:
# - send: 50000
# to: 5000
# - send: 7777
# to: 777
# protocol: udp
这是我的虚拟主机文件:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName homestead.client1.co.uk
ServerAlias www.homestead.client1.co.uk
DocumentRoot /srv/www/vhosts/homestead.client1.co.uk/public
<Directory /srv/www/vhosts/homestead.client1.co.uk/public>
AllowOverride All
Require all granted
</Directory>
# code added
Alias /project-one /srv/www/vhosts/homestead.client1.co.uk/project-one/public
<Directory "/srv/www/vhosts/homestead.client1.co.uk/project-one/public">
Options None
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
# code added
<IfModule mod_fastcgi.c>
AddHandler php7.3-fcgi .php
Action php7.3-fcgi /php7.3-fcgi
Alias /php7.3-fcgi /usr/lib/cgi-bin/php7.3
FastCgiExternalServer /usr/lib/cgi-bin/php7.3 -socket /var/run/php/php7.3-fpm.sock -pass-header Authorization
</IfModule>
<IfModule !mod_fastcgi.c>
<IfModule mod_proxy_fcgi.c>
<FilesMatch ".+\.ph(ar|p|tml)$">
SetHandler "proxy:unix:/var/run/php/php7.3-fpm.sock|fcgi://localhost"
</FilesMatch>
</IfModule>
</IfModule>
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/homestead.client1.co.uk-error.log
CustomLog ${APACHE_LOG_DIR}/homestead.client1.co.uk-access.log combined
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
我对虚拟主机所做的唯一修改是在 # code added
.
我在服务器根目录中放置了一个 index.php
文件,显示 phpinfo();
:
vagrant@homestead:~$ ls -la /srv/www/vhosts/homestead.client1.co.uk/public/
total 4
drwxr-xr-x 1 vagrant vagrant 96 Sep 8 05:14 .
drwxr-xr-x 1 vagrant vagrant 160 Sep 8 05:07 ..
-rw-r--r-- 1 vagrant vagrant 17 Sep 7 05:10 index.php
在浏览器中我可以访问 http://homestead.client1.co.uk/index.php
并成功看到它的输出,所以服务器工作正常。
但是,如果我使用 http://homestead.client1.co.uk/project-one/index.php
请求 'Alias' 目录,我会收到 404 未找到响应。
我可以确认项目文件位于 vhost 别名中指定的位置并且权限设置正确:
vagrant@homestead:~$ ls -la /srv/www/vhosts/homestead.client1.co.uk/project-one/public/
total 28
drwxr-xr-x 1 vagrant vagrant 192 Sep 7 06:41 .
drwxr-xr-x 1 vagrant vagrant 96 Sep 7 06:40 ..
drwxr-xr-x 1 vagrant vagrant 96 Sep 7 06:41 css
drwxr-xr-x 1 vagrant vagrant 480 Sep 7 06:41 images
-rw-r--r-- 1 vagrant vagrant 24679 Sep 7 06:40 index.php
drwxr-xr-x 1 vagrant vagrant 96 Sep 7 06:40 libs
如您所见,'project-one' 不是 laravel 框架,它是一个用于测试目的的简单静态登录页面。
任何帮助解决问题都将非常有用,谢谢。
错误日志是否显示任何内容?
您可以尝试在 project-one 别名下添加 Require All Granted
,如下所示:
Alias /project-one /srv/www/vhosts/homestead.client1.co.uk/project-one/public
<Directory "/srv/www/vhosts/homestead.client1.co.uk/project-one/public">
Options None
AllowOverride All
Order Deny,Allow
Allow from all
Require all granted
</Directory>