403错误-Apache VirtualHost -Ubuntu 22.04

发布于 2025-01-26 21:46:51 字数 612 浏览 2 评论 0原文

我最近安装了Ubuntu 22.04,并尝试在其上使用灯。 但是我对VirtualHost有问题。 我想在以下本地域中使用VirtualHosts:test.local 我将此域添加到 /etc /hosts中,然后将此配置添加到我的test.local.conf:

<VirtualHost *:80>
        ServerName test.local
        ServerAdmin webmaster@localhost
        DocumentRoot /home/soroush/Sites/test
        <Directory "/home/soroush/Sites/test" >
           Order allow,deny
           Allow from all
           Require all granted
        </Directory>
</VirtualHost>

然后运行:a2ensite test.local.conf 但是,当我打开测试时。局域网在浏览器中,Apache向我显示了403个错误。 站点/测试文件夹和文件具有0777权限,所有者是我的用户名。 解决此问题我该怎么办?

i recently install ubuntu 22.04 and try to use LAMP on it.
but i have problem with VirtualHost.
i want use virtualhosts with a local domain like: test.local
i added this domain to /etc/hosts and add this configuration to my test.local.conf:

<VirtualHost *:80>
        ServerName test.local
        ServerAdmin webmaster@localhost
        DocumentRoot /home/soroush/Sites/test
        <Directory "/home/soroush/Sites/test" >
           Order allow,deny
           Allow from all
           Require all granted
        </Directory>
</VirtualHost>

and then run: a2ensite test.local.conf
but when i open test.local in my browser, apache show me a 403 error.
Sites/test folder and files have 0777 permission and owner is my username.
what i should to do for fix this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

盗琴音 2025-02-02 21:46:51

将您的用户添加到Apache组,然后工作正常

sudo usermod -g www -data&lt; your_username&gt;

Add your user to the apache group then it's working fine

sudo usermod -g www-data <YOUR_USERNAME>

软甜啾 2025-02-02 21:46:51

默认情况下,Ubuntu不允许通过Web浏览器访问
位于 /var /www,public_html目录中的任何文件
(启用时)和 /usr /共享(用于Web应用程序)。如果您的网站是
使用位于其他地方的W​​eb文档根(例如 /srv),您可以
需要在文档中白色文档root目录
/etc/apache2/apache2.conf。默认的ubuntu文档根为
/var/www/html。您可以在/var/www.

下制作自己的虚拟主机

这与以前提供更好安全性的发行版不同
开箱即用。

解决问题:

  1. 将源代码移至/var/www

    示例:/var/www/site

2.将您的VirtualHost提交

<VirtualHost *:80>
  ServerName test.local
  ServerAdmin webmaster@localhost
  DocumentRoot /var/www/site
  <Directory "/var/www/site" >
    Order allow,deny
    Allow from all
    Require all granted
  </Directory>
</VirtualHost>

By default, Ubuntu does not allow access through the web browser to
any file apart of those located in /var/www, public_html directories
(when enabled) and /usr/share (for web applications). If your site is
using a web document root located elsewhere (such as in /srv) you may
need to whitelist your document root directory in
/etc/apache2/apache2.conf. The default Ubuntu document root is
/var/www/html. You can make your own virtual hosts under /var/www.

This is different to previous releases which provides better security
out of the box.

To solve the problem:

  1. Move your source code to /var/www

    Example: /var/www/site

2.Fix your Virtualhost

<VirtualHost *:80>
  ServerName test.local
  ServerAdmin webmaster@localhost
  DocumentRoot /var/www/site
  <Directory "/var/www/site" >
    Order allow,deny
    Allow from all
    Require all granted
  </Directory>
</VirtualHost>
迟到的我 2025-02-02 21:46:51

所有TIHS信息都可以,我只在 /etc /hosts文件中添加一排我的网站:

127.0.0.1 my-Site

All tihs info are ok, I only add a row of my site into the /etc/hosts file:

127.0.0.1 my-site

辞取 2025-02-02 21:46:51

我的求解是降级到20.04;)对不起,如果我不能给您更好的解决方案。

my soluttion was a downgrade to 20.04 ;) sorry if I can't give you a better solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文