Nginx配置子域和论坛

时间:2016-11-08 17:54:50

标签: nginx subdomain

我正在尝试配置nginx以执行以下操作:

  • 将example.com和www.example.com重定向到我的旧网站
  • www.example.com/forum或example.com/forum到论坛网络服务器(ip)
  • .example.com的任何其他子域,反向代理到node.js

我知道以下不起作用,我该如何配置?

server {
    listen 80;
    server_name www.example.com example.com;

    location /forum {
        proxy_pass http://<forum ip>/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    return 301 $scheme://www.old-website.com;
}
server {
    listen 80;

    server_name ~^(.*)\.example\.com $;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

1 个答案:

答案 0 :(得分:2)

%-matrix data([[1,2,18,23], [5,6,10,10], [9,10,11,12], [13,14,15,16]]). %-Sum main(S):- data(Ms), length(Ms,N), Mdl is N//2, sum_matr(Ms,1,N,Mdl,0,S). %+Matrix,+RowCounter,+Length,+Midle,+Acc,-S sum_matr([R|Rs],I,K,Mdl,Acc,S):- I=<Mdl, I1 is I+1, findEnd(R,Mdl,ResList), sum_row(ResList,Mdl,I,K,0,Srow), Acc1 is Acc + Srow, sum_matr(Rs,I1,K,Mdl,Acc1,S). sum_matr(_,I,_,Mdl,S,S):- I>Mdl. %+Row,+Counter,+I,+K,+Acc,-Sum sum_row([X|Xs],C,I,K,Acc,S):- C<K, Acc1 is Acc+X, C1 is C+1, sum_row(Xs,C1,I,K,Acc1,S). sum_row(_,C,_,K,S,S):- C>=K. %+List, +Position, -End findEnd(E, 0, E). findEnd([_|T], N, E):- N>0, N1 is N-1, findEnd(T, N1, E). 将阻止return 301块被考虑。尝试将其包装在默认位置块中:

location /forum