【问题标题】:Getting Nginx to point to a specific index.html page outside of /var/www/让 Nginx 指向 /var/www/ 之外的特定 index.html 页面
【发布时间】:2014-09-17 05:17:32
【问题描述】:

我试图让 nginx 指向我的 index.html 页面以及位于 /var/www/ 之外的 GoPATH 中的 imgs、CSS、JS 等。我的总体目标是让我的网站在端口 80 而不是 8080 上运行。可以这样做吗?以下是我目前在 nginx.conf 中的内容。

user www-data;

    http {
            include /etc/nginx/proxy.conf;
            index   index.html
    }

                  server { # simple reverse-proxy
            listen       80;
            server_name  dtrinh.com www.dtrinh.com;
            access_log   logs/dtrinh.access.log  main;

            # serve static files
            # serve static files
            location /  {
              root    /go/src/ps/views/default/index.html;
              expires 30d;

            # pass requests for dynamic content to rails/turbogears/zope, et al
            location / {
              proxy_pass      http://127.0.0.1:8080;
            }

        }

【问题讨论】:

  • 您只是想提供一个文件吗? “index.html”或整个默认目录。
  • 我正在尝试服务整个目录,也就是 ps,其中包含 index.html、css 等。
  • 顺便说一句,您在此处发布的配置不正确。第 6 行有一个杂散的 }。

标签: nginx reverse-proxy


【解决方案1】:
location / {
    root /go/src/ps/views/default;
    error_page 404 = @backend;
    expires 30d;
}

location @backend {
    proxy_pass http://127.0.0.1:8080;
}

参考:

【讨论】:

  • 您的根目录是正确的,但发帖人说他想为整个目录提供服务,因此请使用位置 / 更新您的答案。但我认为它会与后来的位置发生冲突。因此,您需要向 OP 询问“静态内容”的定义以构建正则表达式。
  • 我已经改变了答案。
猜你喜欢
  • 2020-07-04
  • 2016-05-27
  • 2012-01-05
  • 1970-01-01
  • 2013-04-03
  • 2011-09-13
  • 2017-01-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多