Jackeroo
Jackeroo

Reputation: 95

Can multi laravel based sites be accessed by folder not by port?

Now, I have two projects(sites) based on Laravel + PHP + MySQL + Nginx, vistors can access them by typing:

  http://www.mysite.com:80
  http://www.mysite.com:8001

Can I change the accessing method to virtual folder not by port?

  http://www.mysite.com/project1
  http://www.mysite.com/project2

The nginx conf files are (at /etc/nginx/conf.d/):

Upvotes: 2

Views: 650

Answers (2)

Timo Stark
Timo Stark

Reputation: 3071

Sure - an example config will look like this:

1 Define your app servers

server {
 listen 8080;
 root /var/www/html/project1/public;
  ......
}
server {
 listen 8081;
 root /var/www/html/project2/public;
  ......
}

2 Define your proxy server

server {
 listen 80;
 server_name mysite.com www.mysite.com;
 .....
 location /project1 {
    proxy_pass http://localhost:8080;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    .....
  }


  location /project2 {
    proxy_pass http://localhost:8081;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    ....
  }
}

Upvotes: 0

JG Estiot
JG Estiot

Reputation: 1031

The only decent way to do it is by folder and virtual host rather than port.

Upvotes: 0

Related Questions