在启用SSL的情况下,Nginx只提供索引页

nfzehxib  于 2023-05-16  发布在  Nginx
关注(0)|答案(1)|浏览(150)

我正在尝试为ssl配置配置nginx.conf。我的UI静态内容在/usr/share/nginx/html中。之前我可以通过http加载所有页面,但是当我启用https时,它只提供index页面,其他页面显示404 Not Found nginx 404默认页面。我在任何地方都没有任何sites-available文件夹。看起来我缺少任何次要配置。请帮助我,我在哪里犯了错误。我使用nginx:alpine docker镜像作为基础。所有静态页面/内容都存在于/usr/share/nginx/html下,并在/**上提供服务,后端使用带有uri /api/**的API调用提供服务
/etc/nginx/conf.d/default.conf

server {
  listen 80 default_server;
  listen [::]:80 default_server;
  server_name _;
  return 301 https://$host$request_uri;
}
server {
  listen 443 ssl default_server;
  listen [::]:443 ssl default_server;
  ssl_certificate /etc/nginx/certificate/nginx-certificate.crt;
  ssl_certificate_key /etc/nginx/certificate/nginx.key;
  server_name _;
  location / {
    root /usr/share/nginx/html;
      index index.html index.htm;
  }
  location /api {
    proxy_pass https://my-aws-ec2-instance.com;
  }
  location /em {
    proxy_pass https://my-aws-s3-instance.com;
  }
}

/etc/nginx/nginx.conf

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}
goucqfw6

goucqfw61#

添加try_files后,它工作了。

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

看起来像在nginx上重试它通过,但不确定它是否会创建另一个级联问题。

相关问题