Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nginx conf example #1

Open
willin opened this issue Mar 8, 2017 · 8 comments
Open

nginx conf example #1

willin opened this issue Mar 8, 2017 · 8 comments
Labels

Comments

@willin
Copy link

willin commented Mar 8, 2017

can you give me a config example of nginx?

server {
        listen 80;
        server_name *.example.com;
  
         location / {
                 proxy_pass http://127.0.0.1:3000/;
                 proxy_redirect off;
         }
}

can this one work perfectly?

@keenwon
Copy link
Owner

keenwon commented Mar 8, 2017

You need to pass Host field to nodejs, koa-subdomain will select different route based on the Host field.

@willin
Copy link
Author

willin commented Mar 8, 2017

server {
        listen 80;
        server_name *.example.com;
  
         proxy_set_header Host $http_host;
         location / {
                 proxy_pass http://127.0.0.1:3000/;
                 proxy_redirect off;
         }
}

like this?

@keenwon
Copy link
Owner

keenwon commented Mar 8, 2017

Almost that, you can try to debug.

@willin
Copy link
Author

willin commented Mar 8, 2017

const Koa = require('koa');
const Subdomain = require('koa-subdomain');
const router = require('koa-route');

const app = new Koa();
const subdomain = new Subdomain();

subdomain.use('*', router.get('/', async (ctx) => {
  ctx.body = ctx.subdomains;
}));

app.use(subdomain.routes());

app.listen(4123);

sub.example.com can visit.

sub.sub.example.com cannot visit.

@keenwon
Copy link
Owner

keenwon commented Mar 8, 2017

sub.sub.example.com will match *.sub.example.com.
Currently, * only match 1 domain offset.

@keenwon keenwon added the feature label Mar 8, 2017
@willin
Copy link
Author

willin commented Mar 8, 2017

最新版本 koa-route

不再需要

new Router()

另外我还有一个疑问,可能你能帮得上,能加个 QQ 微信么

@keenwon
Copy link
Owner

keenwon commented Mar 8, 2017

我突然发现你写的是koa-route,而我一直用的是koa-router,对于koa-router,你不new也可以,他自己会处理的:
https://github.com/alexmingoia/koa-router/blob/5.x/lib/router.js#L44

@willin
Copy link
Author

willin commented Mar 8, 2017

哦。。。不要在意这些细节。。。我有问题要请教。 2539929

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants