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
    • 最新
    • 标签
主页 / user-613046

Baptise's questions

Martin Hope
Baptise
Asked: 2021-02-09 08:16:26 +0800 CST

Nginx 不返回子路径的 css/js

  • 0

我在 k8s 上有一个网站和入口控制器。此配置在返回静态 html / css / json 时起作用:

入口.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: example-com
  annotations:
    kubernetes.io/tls-acme: "true"
    cert-manager.io/cluster-issuer: letsencrypt-prod
    kubernetes.io/ingress.class: kong
spec:
  tls:
  - secretName: example-com
    hosts:
    - example.com
  rules:
  - host: example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: cvsite
            port: 
              number: 80

Nginx.conf

server {
    listen       80;
    server_name  example.com/blog;
    ssl_certificate     /etc/nginx/certs/tls.crt;
    ssl_certificate_key /etc/nginx/certs/tls.key;
    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers         HIGH:!aNULL:!MD5;
    include /etc/nginx/mime.types;
    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

但是添加这 3 行会破坏一切:

入口.yaml

paths:
      - path: /cv      ##CHANGE HERE
        pathType: Prefix
        backend:
          service:
            name: cvsite
            port: 
              number: 80

Nginx.conf

location /cv {                                    #CHANGE HERE
        alias   /usr/share/nginx/html/;            #CHANGE HERE   
        index  index.html index.htm;              
    }

curl -v https://example.com/cv

*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x7fa82200a400)
> GET /cv HTTP/2
> Host: example.com
> User-Agent: curl/7.64.1
> Accept: */*
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
< HTTP/2 404
< content-type: text/html; charset=UTF-8
< content-length: 153
< server: nginx/1.19.6
< date: Mon, 08 Feb 2021 17:40:19 GMT
< x-kong-upstream-latency: 1.9999771118164
< x-kong-proxy-latency: 1
< via: kong/2.2.1
<
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.19.6</center>
</body>
</html>

在浏览器中,https: //example.com/cv 仅返回空白页。

请问 ls /usr/share/nginx/html 显示 index.html 和静态文件时怎么会返回 404?

nginx kubernetes
  • 1 个回答
  • 1581 Views
Martin Hope
Baptise
Asked: 2021-01-19 10:48:31 +0800 CST

使用 NGINX 作为另一个 Nginx 的反向代理

  • 1

我有一个带有 Nginx 的 kubernetes pod,为静态 node.js 网站提供服务,负载均衡器 IP 为 192.168.0.223。当我浏览http://192.168.0.223:80/时,静态网站显示正确。由于本地网络的限制,我在 Raspberry pi Raspbian 上的 192.168.0.199 有一个反向代理 NGINX。这是 Nginx 的配置:

server {
  listen 80;
  listen [::]:80;
  server_name localhost;
  access_log /var/www/logs/node-access.log;
  error_log /var/www/logs/node-error.log;
  location / {
        proxy_pass http://192.168.0.223:80;
        proxy_set_header Host $http_host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Scheme $scheme;
        proxy_redirect http://192.168.0.223/ /;
        client_max_body_size 0;
    }
}

但是,当我请求http://192.168.0.199:80/时,它会显示香草“欢迎来到 Nginx!” 页。我确保这是启用站点的唯一 conf,并且日志中没有任何内容。请问你能帮帮我吗 ?

nginx raspbian
  • 1 个回答
  • 80 Views

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