Apache Setup Multiple Project On Test Server

不想你离开。 提交于 2021-01-28 12:11:05

问题


I'm using CentOS 7 and Apache on my Virtualbox.

This VM has its own IP address (XXX.XX.XX.XX).

Having this setting below, I can access my project on the browser by typing http://XXX.XX.XX.XX

<VirtualHost *:80>       
  DocumentRoot /var/www/html/project_name/public/       

  <Directory /var/www/html/project_name/> 
    AllowOverride All 
  </Directory> 

  ErrorLog /var/log/apache2/project_name-error_log 
  CustomLog /var/log/apache2/project_name-common_log combined
</VirtualHost> 

My problem is I have another web app project that will run on this machine.

Can I configure wherein the two projects will be accessible using different port numbers like below?

http://192.168.10.1:8001
http://192.168.10.1:8002

SOLUTION:

Here's how I managed it to make it work:

Listen 8001
Listen 8002 

<VirtualHost *:8001> 
ServerName ipaddress:8001 

<VirtualHost *:8002> 
ServerName ipaddress:8002

回答1:


<VirtualHost *:80>
        ServerName www.example.com
        DocumentRoot /var/www/html/project_name/public/
</VirtualHost>
<VirtualHost *:80>
        ServerName example.com
        DocumentRoot /var/www/html/project_name/public/
</VirtualHost>


<VirtualHost *:80>
        ServerName www.abc.com
        DocumentRoot /var/www/html/project_name1/public/
</VirtualHost>
<VirtualHost *:80>
        ServerName abc.com
        DocumentRoot /var/www/html/project_name1/public/
</VirtualHost>

Try this. Inside config you can set multiple domain with different directory on same port 80

Second option running like http://xx.xxx.xxx.xx/project1 and http://xx.xxx.xxx.xx/project2

set up in .htaccess inside project folder

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond  %{REQUEST_URI}  !^/mm.*$
    RewriteRule ^(.*)$ public/$1 [L,QSA]

    RewriteCond  %{REQUEST_URI}  ^/mm.*$
    RewriteRule ^/mm/(.*)$ public/mm/$1 [L,QSA]
</IfModule>
AddDefaultCharset utf-8


来源:https://stackoverflow.com/questions/58968084/apache-setup-multiple-project-on-test-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!