我有一台运行站点的开发和暂存实例的服务器,每个版本都必须在端口80& 443.暂存实例 - 只有一个 - 完全按照我的预期工作,但为每个用户配置的开发实例 - 直接在任一协议上加载给定页面就好了,但如果我在一个端口上的页面,并尝试链接到另一个端口失败。
我的配置
server {
listen 80;
server_name ~^dev\.(?<username>[^.]+)\.client\.tld\.net$
~^(?<username>[^.]+)\.client\.dev\.tld\.net$
~^(?<username>[^.]+)\.dev\.client\.tld\.net$;
location / {
rewrite ^(.*) http://$username.client.tld.net$1 permanent;
}
}
# This is the primary host that will ultimately answer requests.
server {
listen 80;
server_name ~^(?<username>[^.]+)\.client\.tld\.net$;
root /home/$username/client/www/app/webroot;
index index.php;
access_log /var/log/nginx/client.sandbox.access.log;
error_log /var/log/nginx/client.sandbox.error.log;
location / {
try_files $uri $uri/ /index.php?url=$uri;
}
location ~ \.php$ {
include /etc/nginx/conf/php;
}
include /etc/nginx/conf/expire_content;
include /etc/nginx/conf/ignore;
}
server {
listen 443 ssl;
server_name ~^dev\.(?<username>[^.]+)\.client\.tld\.net$
~^(?<username>[^.]+)\.client\.dev\.tld\.net$
~^(?<username>[^.]+)\.dev\.client\.tld\.net$;
location / {
rewrite ^(.*) https://$username.client.tld.net$1 permanent;
}
}
# This is the primary host that will ultimately answer requests.
server {
listen 443 ssl;
server_name ~^(?<username>[^.]+)\.client\.tld\.net$;
root /home/$username/client/www/app/webroot;
index index.php;
include /etc/nginx/conf/ssl;
access_log /var/log/nginx/client.sandbox.access.log;
error_log /var/log/nginx/client.sandbox.error.log;
location / {
try_files $uri $uri/ /index.php?url=$uri;
}
location ~ \.php$ {
include /etc/nginx/conf/php;
}
include /etc/nginx/conf/expire_content;
include /etc/nginx/conf/ignore;
}
知道我把配置搞定了吗?
答案 0 :(得分:2)
首先,不需要创建四个单独的配置,因为您的服务器(HTTP和HTTPS)具有完全相同的主体。您可以根据您正在使用的上下文(对于重定向)使用包含$scheme
或http
的{{1}}变量。其次,我在https
配置中没有看到任何root
声明,也没有可能导致浏览器出现问题的证书。
除此之外,配置对我来说没问题(好吧,你可以将dev
声明移到你的index
配置中;所以你不必一直重复它。)
请查看我为您准备的以下(注释)示例配置。也许有帮助。
http