使用NGINX将Gatsby托管在子目录上 [英] Hosting Gatsby on a subdirectory using NGINX

查看:139
本文介绍了使用NGINX将Gatsby托管在子目录上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用nginx将gatsby.js托管在子目录中,我已经尝试使用proxy_pass http://127.0.0.1:8000gatsby develop来做到这一点,但是Socket.io却遇到了问题.有谁知道如何在下面使用的重写代码rewrite ^([^.\?]*[^/])$ $1/ permanent尝试将gatsby托管在一个子目录中.但这无济于事.

How do i host gatsby.js on a subdirectory using nginx, i have already tried to do this using proxy_pass http://127.0.0.1:8000 with gatsby develop but i'm facing issues with Socket.io. Does anyone know how to host gatsby on a subdirectory i've tried using the following rewrite code rewrite ^([^.\?]*[^/])$ $1/ permanent. But that does nothing.

好的,起初我使用gatsby develop以便可以使用HMR,但是我猜乞be不能成为选择者,因此根据fabian所说的,我做了以下事情.

Okay so at first i was using gatsby develop so that i can make use of HMR, but i guess beggars can't be choosers, so based on what fabian said, i did the following.

这就是我所做的,最终,

Here is what i did, ultimately,

我在gatsby-config.js文件中添加了行pathPrefix: '/blog'

我在项目的主目录中运行gatsby build --prefix-paths

I ran gatsby build --prefix-paths on the home directory of my project

然后将public文件夹中的内容复制到我的网站根目录中的一个名为blog的文件夹中,它可以正常工作(没有HMR).

And copied the contents on the public folder moved to a folder called blog in the root directory of my website and it works perfectly (without HMR, that's).

推荐答案

GatsbyJS是静态站点 generator ,这意味着它可以输出静态HTML,CSS和JS.您实际上不需要设置NodeJS服务器来使其运行. gatsby develop应该仅在开发中(本地)使用,而不是在生产中使用.

GatsbyJS is a static site generator, which means it outputs static HTML, CSS and JS. You don't actually need to set up a NodeJS server to make it run. gatsby develop should only be used in development (locally), not in production.

基本上,您将要运行gatsby build并将本地public目录内的所有文件移动/上载到服务器上的子目录.当然,该子目录需要公开地可通过NGINX ,Apache或类似服务器获得/提供.例如:

Basically, you'll want to run gatsby build and move/upload all the files inside the local public directory to the subdirectory on your server. Of course, that subdirectory needs to be publicly available/served via NGINX, Apache or similar. For example by:

location /subdirectory {
  root /html/my-site/public;
  index.html;
}

找到在此处部署GatsbyJS的更多详细信息.另外,请不要忘记添加路径前缀.

Find more details on deploying GatsbyJS here. Also, don't forget to add a Path Prefix.

这篇关于使用NGINX将Gatsby托管在子目录上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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