Link 2 个域到 1 个 Laravel 通过 Nginx 的项目
Link 2 domains to 1 Laravel project via Nginx
我正在尝试 link 我现有项目的另一个域
我正在使用 Laravel 5.1,我知道我们在 .env.
中只有一个 APP_URL
有没有办法通过 Nginx 级别来完成?
猫/etc/nginx/sites-available/default
server {
listen 80 default_server;
server_name default;
root /home/forge/bheng/public;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/default-error.log error;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
如何配置这样的东西?
您为两个域指定了相同的 webroot。在 Laravel 代码中,您使用域组或 url('/')
来检查您所在的域。
您的配置可能如下所示:
server {
listen 80, 443;
listen [::]:80, [::]:443;
servername www.domain1.com www.domain2.com;
root /home/kyo/laravel/public/;
index index.php;
location / {
try_files $uri $uri/ =404;
}
}
在服务器名称配置中将这两个域作为别名
server_name domain1.com www.domain1.com domain2.com www.domain2.com ;
我使用了类似这样的服务器名称别名:
server_name www.app1 www.app2;
然后让 DNS 指向同一个主机。如果您在自己的 linux 框中工作,请更改 /etc/hosts
文件:
sudo vim /etc/hosts
并添加新主机:
127.0.0.1 www.app1
127.0.0.1 www.app2
我正在尝试 link 我现有项目的另一个域
我正在使用 Laravel 5.1,我知道我们在 .env.
中只有一个APP_URL
有没有办法通过 Nginx 级别来完成?
猫/etc/nginx/sites-available/default
server {
listen 80 default_server;
server_name default;
root /home/forge/bheng/public;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/default-error.log error;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
如何配置这样的东西?
您为两个域指定了相同的 webroot。在 Laravel 代码中,您使用域组或 url('/')
来检查您所在的域。
您的配置可能如下所示:
server {
listen 80, 443;
listen [::]:80, [::]:443;
servername www.domain1.com www.domain2.com;
root /home/kyo/laravel/public/;
index index.php;
location / {
try_files $uri $uri/ =404;
}
}
在服务器名称配置中将这两个域作为别名
server_name domain1.com www.domain1.com domain2.com www.domain2.com ;
我使用了类似这样的服务器名称别名:
server_name www.app1 www.app2;
然后让 DNS 指向同一个主机。如果您在自己的 linux 框中工作,请更改 /etc/hosts
文件:
sudo vim /etc/hosts
并添加新主机:
127.0.0.1 www.app1
127.0.0.1 www.app2