簡體   English   中英

帶有目錄的 Apache 虛擬主機 uri

[英]Apache virtual host uri with a dir

我無法使用子目錄在 url 上設置虛擬主機......我需要在這樣的地址上運行我的項目:

http://www.projects.loc/project1/這應該模擬在 Web 服務器上的安裝,其中的地址將類似於

http://www.someServer.com/projects/project1/

我需要將重定向調整為“/”,以便返回到www.projects.loc/project1/

在 hosts.txt 我有:

127.0.0.1       www.projects.loc

vhosts 已啟用,httpd-vhosts.conf 如下所示:

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot "D:/Projects/Project1/public/"         
    ServerName  www.projects.loc/project1/
</VirtualHost>

我錯過了什么?

編輯: .htaccess 看起來像這樣:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php [NC,L]

該應用程序在干凈的域上正常運行,但我無法將其配置為在 domain.com/some_dir/ 上運行

編輯:
解決了這個!

NameVirtualHost *:80   

   <Directory "D:/Projects"> 
      allow from all
   </Directory>

    <VirtualHost *:80>
        DocumentRoot "D:/Projects"      
        ServerName  www.projects.loc/

        Alies /project1  /Project1/public/
    </VirtualHost>

注意:這是僅適用於開發環境的最小配置,
檢查來自@Mz 的接受的 ansler,了解生產環境的完整詳細信息。

可能你已經解決了這個問題。 無論如何,我今天正在尋找類似的東西,因此我在這里記錄了解決方案:

您不想在 ServerName 中寫入斜杠

ServerName  www.projects.loc/project1/

如果您只有一個名為“project1”的項目,您可以使用“ServerPath”輕松完成工作,您的虛擬主機配置將如下所示:

<VirtualHost *:80>
  ServerName projects.loc
  ServerAlias www.projects.loc
  ServerPath /project1/
  DocumentRoot /PATH/public_html
  ErrorLog /PATH/error_log
  CustomLog /PATH/access_log combined
  DirectoryIndex index.html index.htm index.php index.php4 index.php5

  <Directory /PATH/public_html>
    Options -Indexes +IncludesNOEXEC +FollowSymLinks
    allow from all
  </Directory>

</VirtualHost>

通過 ServerPath,您可以將目錄掛載到 projects.loc/project1

無論如何,假設您有幾個項目(project1、project2)要綁定到 projects.loc/project1、projects.loc/project2 等,請使用“別名”。 您的 vhost 配置文件應如下所示:

<VirtualHost *:80>
  ServerName projects.loc
  ServerAlias www.projects.loc
  DocumentRoot /PATH/public_html
  ErrorLog /PATH/error_log
  CustomLog /PATH/access_log combined
  DirectoryIndex index.html index.htm index.php index.php4 index.php5

  <Directory /PATH/public_html>
    Options -Indexes +IncludesNOEXEC +FollowSymLinks
    allow from all
  </Directory>

  Alias /project1 "/PATH/public_html/project1"
  <Directory "/PATH/public_html/project1">
    DirectoryIndex index.html index.htm index.php index.php4 index.php5
    Options -Indexes +IncludesNOEXEC +FollowSymLinks
    allow from all
  </Directory>

  Alias /project2 "/PATH/public_html/project2"
  <Directory "/PATH/public_html/project2">
    DirectoryIndex index.html index.htm index.php index.php4 index.php5
    Options -Indexes +IncludesNOEXEC +FollowSymLinks
    allow from all
  </Directory>

</VirtualHost>

位於文件夾 /PATH/public_html/project1 中的應用程序將在 projects.loc/project1 中可用,位於文件夾 /PATH/public_html/project2 中的應用程序將在 projects.loc/project2 中可用,依此類推。

我寧願為不同的應用程序使用不同的子域。 這樣做的好處是每個子域主機都有自己的配置文件,這也使錯誤和訪問日志處理更容易。 通過使用別名,如果您希望每個應用程序擁有它們,配置不同的錯誤和訪問日志將更加困難。

進一步閱讀:
關於別名: http : //httpd.apache.org/docs/current/mod/mod_alias.html
關於服務器路徑: http : //httpd.apache.org/docs/2.2/vhosts/examples.html#serverpath

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM