【问题标题】:403 Forbidden + Nginx + Virtual Host configuartion + NodeJS403 Forbidden + Nginx + 虚拟主机配置 + Node JS
【发布时间】:2019-03-22 01:25:31
【问题描述】:

我在使用 Nginx 为 NodeJS 应用程序配置服务器虚拟主机时收到 403 Forbidden。

配置文件代码:

server {
  listen 443 default_server;
  listen [::]:443 default_server;

  ssl on;
  ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
  root /mnt/var/www/example.com/app/public/;

  index index.html index.htm index.php;

  server_name example.com www.example.com;

    access_log  /var/log/nginx/dygnostica_access.log;
    error_log   /var/log/nginx/dygnostica_error.log;

  location / {
    include /etc/nginx/proxy_params
    try_files $uri $uri/ =404;
  }
}

server {
   listen 0.0.0.0:80;
   server_name example.com www.example.com;
   rewrite ^ https://$host$request_uri? permanent;
}

我已经根据this 文章设置了所有配置。

需要帮助解决 403。提前致谢。

编辑:

错误日志说:

“/mnt/var/www/example.com/app/public/”的目录索引被禁止。

【问题讨论】:

  • 编辑您的问题并从您的访问日志和错误日志中添加相关条目。您问题中的代码缺少; - 这只是问题或配置中的错字吗?
  • @RichardSmith,我添加了错误日志。并且可能我需要提供此行的特定路径:“root /mnt/var/www/example.com/app/public/;”但我不知道如何给出确切的路径。
  • 那么 nginx 是否有权查看该文件夹?

标签: node.js nginx error-handling virtualhost http-status-code-403


【解决方案1】:

我认为您对虚拟主机的配置有误。这是我的 nginx 配置文件。我在主域上有标准 PHP 应用程序 (https),​​在子域上有节点应用程序(在端口 3000 上运行):

#// virtual host for node app:
server {
  server_name node.domain.cz;
  location / {
  proxy_pass http://127.0.0.1:3000;
  }
}

#// host (for PHP app)
server {
        listen 80;
        server_name domain.cz www.domain.cz;
        root /var/www/domain.cz/www;
        index index.php;

        location / {
                try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/run/php/php7.1-fpm.sock;
                fastcgi_index index.php;
                include fastcgi.conf;
        }

    listen 443 ssl; # managed by Certbot
    # ssl_certificate ...

    if ($scheme != "https") {
        return 301 https://$host$request_uri;
    } # managed by Certbot

}

【讨论】:

  • Zaruba 我也配置了标准配置,但只需要为“root /mnt/var/www/example.com/app/public/”行提供目录特定路径即可。
猜你喜欢
  • 2011-10-16
  • 2011-02-22
  • 2011-05-14
  • 2015-01-23
  • 2012-12-24
  • 1970-01-01
  • 1970-01-01
  • 2014-11-12
  • 2011-08-17
相关资源
最近更新 更多