【问题标题】:Alias on Ubuntu Apache2 site on server no domain name服务器上的 Ubuntu Apache2 站点上的别名没有域名
【发布时间】:2018-10-04 08:27:37
【问题描述】:

我在 3 个确实有域名的网站上使用了这种方法,并且一切正常。目前我正在开发另一个没有域名但完全可以通过服务器 IP 访问的网站,所以:

195.111.111.111/mywebsite.com/

而不是http://mywebsite.com/

我猜你明白了 :) 无论如何,所有网站都共享同​​一个上传文件夹,因为其中包含 300.000 多张照片,我不想上传多个副本。

它适用于所有网站,除了这个没有域名的网站,我猜它的工作方式不同。

当我去:

195.111.111.111/mywebsite.com/product-image

我只是在我的 php 文件中收到一个错误,即无法找到需要一次,这显然是正确的,但重点是......我的 PHP 甚至不应该能够从这个 URL 获取请求,因为我有一个别名,但它转到了 PHP。

谁能告诉我我做错了什么?我当前的配置文件如下:

ServerAdmin webmaster@localhost
DocumentRoot /var/www/mywebsite.nl/

#ServerName mywebsite.nl
#ServerAlias www.mywebsite.nl

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias "/product-image" "/var/www/uploads"

<Directory /var/www/mywebsite.nl/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

RewriteEngine on
RewriteCond %{SERVER_NAME} =mywebsite.nl [OR]
RewriteCond %{SERVER_NAME} =mywebsite.nl
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

【问题讨论】:

  • 那是因为当您转到/product-image 时,服务器会加载位于/var/www/uploads 中的index.php 文件
  • 是的,我想通了,但我该怎么做才能使用别名而不是另一个? :D
  • 顺便说一句,那个位置没有 index.php 文件,只有文件夹和图片。它不会去 /var/www/uploads/ 它去网站本身而不是别名:(
  • 您成功解决了您的问题吗?我认为您需要为您的Alias 创建一个&lt;Directory&gt; 指令。 check this

标签: ubuntu server alias


【解决方案1】:

我在 Ubuntu 服务器上安装 SquirrelMail 后,它编写了一个 Apache 配置文件,如下所示:

Alias /squirrelmail /usr/share/squirrelmail

<Directory /usr/share/squirrelmail>
  Options FollowSymLinks
  php_flag register_globals off
  DirectoryIndex index.php
</Directory>

如果我们将它应用到您的项目中,我们会得到一个如下所示的 Apache 配置文件:

ServerAdmin webmaster@localhost
DocumentRoot /var/www/mywebsite.nl/

ServerName mywebsite.nl
ServerAlias www.mywebsite.nl

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /product-image /var/www/uploads

<Directory /var/www/mywebsite.nl>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
</Directory>

<Directory /var/www/uploads>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
</Directory>

我所做的更改:

  1. 我更改了别名路径,现在它们没有引号。
  2. 我将Order allow,denyallow from all 更改为Require all granted
  3. 我为/var/www/uploads 创建了一个&lt;Directory... 指令。

【讨论】:

    猜你喜欢
    • 2021-03-27
    • 1970-01-01
    • 2021-10-04
    • 1970-01-01
    • 2014-07-25
    • 1970-01-01
    • 2017-12-14
    • 2016-03-23
    • 1970-01-01
    相关资源
    最近更新 更多