nginx子域配置example.com/blog [英] nginx subdomain configuration example.com/blog

查看:127
本文介绍了nginx子域配置example.com/blog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我昨天和今天整整一天都在学习nginx的工作方式,我有两个不同的域,一个是Ghost博客平台,另一个是静态页面(未来的NodeJS应用),现在我试图设置子域,但是我有点沮丧,因为我感觉自己快要到了,但是它不起作用...这是我当前的设置:

I've spent all day yesterday and today learning how nginx works and I got two different domains working, one with Ghost blogging platform and a static page (future NodeJS app), now I'm trying to setup the subdomain, but I'm kind of frustrated because I feel like I'm almost there but it's not working... This is my current setup:

#Main Domain
server {
    listen 80;
    listen [::]:80;

    server_name example.com;
    root /var/www/portfolio;
    index index.html;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
#        proxy_pass http://127.0.0.1:2222;

    }

    location ~ /.well-known {
        allow all;
    }

    client_max_body_size 50m;
}


#Sub domain
server {
    listen 80;
    listen [::]:80;

    server_name example.com/blog;
    root /var/www/ghost/system/nginx-root;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://127.0.0.1:2368;

    }

    location ~ /.well-known {
        allow all;
    }

    client_max_body_size 50m;
}

这个想法是创建mysite.com/blog,最终mysite将是一个nodejs应用程序,以后连接该路由的问题将是另一个问题,但是……一次,大声笑,我如何建立该子域? 如果我将配置文件分成一个单独的文件,则其他域将正常工作:/

The idea is to create mysite.com/blog where eventually mysite would be a nodejs app, prob linking the route later will be another problem but... one at a time lol, how can I establish that subdomain? If I separate the config file into a separate file, I would get the other domain working :/

谢谢

我发现使用AWS上S3中的存储桶可以完成此操作,但是现在我不需要jeje做它,但这很高兴.

I've found that with bucket in S3 on AWS I could acomplish that, but now I don't need it for what I'm doing jeje, but it's good to know.

推荐答案

注意:这不是一个完整的答案,您可能需要修补一下

Note: This is not a complete answer, you probably will need to tinker a bit

正如@Jonathan所提到的,从nginx的角度来看,这是一个站点,但是您需要nginx来以不同的方式处理这两个位置.

As @Jonathan mentioned, from nginx's point of view this is the same site, but you need nginx to handle both locations differently.

这是它的样子

server {
    listen 80;
    listen [::]:80;

    server_name example.com;
    root /var/www/portfolio;
    index index.html;
    client_max_body_size 50m;

    location / {
      # your normal location settings
    }


    # your blog is defined here
    location /blog {
      root /var/www/ghost/system/nginx-root;

      # You'll probably need to do a rewrite here, because a
      # /blog/article needs to be passed as `/article` to the
      # app server

      # rewrite ^/blog/(.*) $1;

      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header Host $http_host;
      proxy_pass http://127.0.0.1:2368;
    }
  }
}

这篇关于nginx子域配置example.com/blog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆