AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 826079
Accepted
barfurth
barfurth
Asked: 2017-01-14 03:18:22 +0800 CST2017-01-14 03:18:22 +0800 CST 2017-01-14 03:18:22 +0800 CST

nginx 只能提供来自子目录的静态文件,而不是网站根目录(500 错误)

  • 772

我没有使用任何框架或任何东西。我试图将我的 style.css 放在与 index.html 相同的目录中(加载正常),但是当我尝试访问它时会引发 500 错误。所以https://example.com/index.html加载正常(没有样式),但访问https://example.com/style.css会引发 500 内部服务器错误。奇怪的是,如果我将样式表放入子目录中,它会起作用,因此https://example.com/styles/style.css可以正常加载。

这是我的站点配置(虚拟主机):

server {
    listen 80;
    server_name example.com www.example.com;

    location / {
        return 301 https://$host$request_uri;
    }

    location /.well-known {
        alias /usr/share/nginx/html/.well-known;
        allow 0.0.0.0;
        deny all;
    }
}

server {
    listen 443;
    server_name example.com www.example.com;

    root /home/deployer/example.com;

    ssl on;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    include includes/ssl;

    try_files $uri/index.html $uri;

    error_page 500 502 503 504 /500.html;
    client_max_body_size 4G;
    keepalive_timeout 10;
}

错误日志

2017/01/13 06:25:46 [error] 1279#0: *182 rewrite or internal redirection cycle while internally redirecting to "/style.css", client: 0.0.0.0, server: example.com, request: "GET /style.css HTTP/1.1", host: "example.com"
2017/01/13 06:25:47 [error] 1279#0: *183 rewrite or internal redirection cycle while internally redirecting to "/favicon.ico", client: 0.0.0.0, server: example.com, request: "GET /favicon.ico HTTP/1.1", host: "example.com", referrer: "https://example.com/style.css"

访问日志

0.0.0.0 - - [13/Jan/2017:06:25:46 -0500] "GET /style.css HTTP/1.1" 500 603 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36"
0.0.0.0 - - [13/Jan/2017:06:25:47 -0500] "GET /favicon.ico HTTP/1.1" 500 603 "https://example.com/style.css" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36"
virtualhost nginx css
  • 1 1 个回答
  • 2352 Views

1 个回答

  • Voted
  1. Best Answer
    13dimitar
    2017-01-14T03:36:09+08:002017-01-14T03:36:09+08:00

    查看http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files - 尝试修改try_files $uri/index.html $uri;为try_files $uri/index.html $uri/ =404;

    • 0

相关问题

  • 阿帕奇虚拟主机

  • Apache:对多个虚拟主机使用相同的目录指令

  • Apache 中的动态虚拟主机

  • VirtualHost / NameVirtualHost 背后的逻辑是什么

  • 如何设置 Jetty 6 和 Jboss 4.0.5 虚拟主机?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve