google-app-engine - 使用 Nginx 托管 Docusaurus v2

标签 google-app-engine nginx docusaurus

我正在尝试使用 nginx 作为反向代理在 Google AppEngine 上托管 Docusaurus v2。 GooglAppEngine 已启用 HTTPS。 Nginx 监听端口 8080。因此默认情况下,所有请求都通过 HTTPS 进行,并且连接由 Google AppEngine 管理。

但是,当用户执行以下操作时我遇到问题:

  • 到达目标网页
  • 转到文档(任何页面)。
  • 刷新页面。

用户被定向到端口 8080,而不是 docusaurus 的 https 站点。

无需刷新页面,用户就能够成功导航该网站。当用户点击刷新按钮时,他们就会得到重定向。查看 header 信息,我看到响应将它们指向端口 8080,但我不确定为什么会发生这种情况。

想知道是否有人已成功使用 nginx 设置 Docusaurus v2?

我的 nginx 配置如下:

events {
    worker_connections 768;
}

http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    # Logs will appear on the Google Developer's Console when logged to this
    # directory.
    access_log /var/log/app_engine/app.log;
    error_log /var/log/app_engine/app.log;

    gzip on;
    gzip_disable "msie6";

    server {
        # Google App Engine expects the runtime to serve HTTP traffic from
        # port 8080.
        listen 8080;
        root /usr/share/nginx/www;
        index index.html index.htm;
        location / {
        if ($http_x_forwarded_proto = "http") {
        return 301 https://$server_name$request_uri;
            }
        }
        


    }

最佳答案

这可能是由于 docusaurus 网站链接到的目录没有尾随斜杠 /,导致默认设置为包含端口的重定向。

查看 docusaurus 构建目录,您将看到您的页面被定义为包含 index.html 文件的文件夹。如果没有 /,服务器需要将您重定向到 {page}/index.html

尝试调用带有 / 且不带端口的 URL,应该会成功:

https://{host}/docs/{page}/

因此,要解决此问题,您可以尝试更改重定向规则,以不包含带有 port_in_redirect 参数的端口:

server {
    listen 8080;
    port_in_redirect off;
    
    # More configuration
    ...
}

请参阅documentation了解更多详情。

关于google-app-engine - 使用 Nginx 托管 Docusaurus v2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62648644/

相关文章:

python - 如何在 Google App Engine Datastore 中存储非 ASCII 字符

laravel - 谷歌应用引擎(GAE)错误: chown: cannot access '/app/public' : No such file or directory

javascript - 如何更正 NginX 反向代理配置中的 Meteor base-url?

node.js - 如何让 ESLint 识别 Docusaurus 别名?

docusaurus - Docusaurus 可以读取文件夹中的所有文件吗?

docusaurus - Docusaurus 中的自定义登录页面

java - 升级 Jersey 版本后随机 REST API 调用失败

java - JSP::与 session 对象混淆

php - Nginx 上的 Yii 框架 - 页面无法加载

reactjs - Nginx docker 容器在 AWS EC2 上托管 reactjs 应用程序 - 未显示