我已经建立了生产站点,现在我正在尝试设置一个开发/暂存站点来运行实时测试。
我在将子域指向 Laravel 应用程序上的正确根路径时遇到问题。
我需要以下内容:
- dev.example.com 指向
root /var/www/dev/public;
- example.com 和 www.example.com 指向根目录 /var/www/laravel/public;
- 目前一切都在
/var/www/laravel/public
服务器:
- Ubuntu 18.10 x64
- Nginx
我有一个域名example.com
,并且我创建了一个名为的子域名,dev.example.com
每个对该域名的引用都通过 certbot/LetsEncrypt 在我的 SSL 证书中。www.example.com、example.com 和 dev.example.com
子域名的 DNS:
A (Record) | dev (Name) | 140.xx.xx.xx (Data)
我这里有两个文件夹:
- /var/www/
laravel
/public (我的主要生产站点) - /var/www/
dev
/public(我的开发网站)
在 sites-available 中/etc/nginx/sites-available
我有具有default
以下配置的文件。
(我尝试过多种变化,但这是我停止的地方)
server {
root /var/www/laravel/public;
index index.php index.html index.htm index.nginx-debian.html;
server_name example.com www.example.com dev.example.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
client_max_body_size 200M;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
# Virtual Host configuration for example.com
server {
if ($host = dev.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name dev.example.com;
root /var/www/dev/public;
return 404; # managed by Certbot
}
server {
if ($host = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name www.example.com;
return 404; # managed by Certbot
}
server {
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 default_server;
listen [::]:80;
server_name example.com;
return 404; # managed by Certbot
}
再次...
我需要
dev.example.com
指出root /var/www/dev/public;
我需要
example.com and www.example.com
指出root /var/www/laravel/public;
如能得到任何帮助以解决此问题,我们将不胜感激。
答案1
您需要创建一个新server
块,以便使用所需的 为新主机名提供服务root
。您可以从现有块复制其余配置,也可以稍后使用include
s 来 DRY 它。