我尝试将NginX设置为使用子域名已经有2天了。
这是我对NginX的“.conf”:
upstream mydomain_staging {
server unix:tmp/unicorn.mydomain_staging.sock fail_timeout=0;
}
server {
listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
root /home/mtaville/mtaville_staging/current/public;
# Make site accessible from http://localhost/
server_name staging.mydomain.fr admin.staging.mydomain.fr;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
deny all;
}
location / {
try_files $uri $uri/index.html $uri.html @mydomain_staging;
}
location @mydomain_staging {
proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
proxy_redirect off;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://mydomain_staging;
}
}
当我尝试访问staging.mydomain.fr时,它可以正常工作!但是当我尝试访问admin.staging.mydomain.fr时,前端显示而不是后端;
这是我的routes.rb:
MyApp::Application.routes.draw do
constraints(subdomain: /admin/) do
match '/', to: 'dashboard#show', as: :admin_root
resources :posts, controller: "admin/posts"
end
root to: "pages#home"
end
我不知道为什么它不起作用!有人帮帮我吗?
非常感谢!