0

我想要公开访问我的上传文件夹,例如:

mydomain.com/uploads/

它需要显示目录中的内容,例如:

mydomain2.com/uploads/id/file.png

这应该显示 file.png

但是当我尝试

mydomain2.com/uploads/

它给了我

403 禁止 nginx/1.15.1

我的 nginx 配置:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;
    return 301 https://$host$request_uri;
}

# mydomain1.com
server {
    listen   443;
    ssl                 on;
    ssl_certificate     /home/opc/Crt/bundle.crt;
    ssl_certificate_key /home/opc/Crt/mydomain1.key;

    server_name mydomain1;
    #root <root_path>;

    location / {
        proxy_pass http://localhost:3001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header X-Forwarded-For $remote_addr;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

#mydomain2.com

server {

  # We are listening on the default port.
  listen 443;

  ssl                 on;
  ssl_certificate     /home/opc/Crt/bundle.crt;
  ssl_certificate_key /home/opc/Crt/mydomain2.com.key;

  # These are the domains we listen on.
  server_name mydomain2.com;

  # The root path
  #root <physical_path>

  location /uploads {
    #internal;
    alias /home/opc/folder/uploads;
    #try_files $uri /uploads/;
    #autoindex on;
    #index index.html;
    #autoindex on;
    #autoindex_exact_size off;
 }

  location / {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_set_header X-Forwarded-For $remote_addr;
  }
}

注意:2 个域指向我的实例,所以我使用一个用于 3001 端口,另一个用于 3000 端口,并且我已将 755 分配给 /folder/uploads 并将 644 分配给上传文件夹中的所有文件

4

1 回答 1

0

看起来您的 nginx 进程没有访问该文件夹/文件的权限,请检查/home/opc/folder/index.html. 执行chown nginx:nginx /home/opc/folder/index.html并运行相同的请求,看看它是如何进行的,如果它仍然有问题,你可能有一些内核访问控制,比如 SELinux,如果你在 CentOS 上运行并且第一次测试失败,chcon -R --reference=/usr/share/nginx/html/ /home/opc/folder然后再试一次。

于 2018-08-06T12:31:50.557 回答