在 Nginx 上部署 Angular 6 应用程序 - 禁止 [英] Deploying Angular 6 app on Nginx - Forbidden

查看:48
本文介绍了在 Nginx 上部署 Angular 6 应用程序 - 禁止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Nginx 部署 Angular 应用

I'm trying to deploy Angular app with Nginx

这是我的 nginx 配置:

Here is my nginx conf:

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name mysite.com;
    root /home/forge/mysite.com/dist/;

    ssl_certificate /etc/nginx/ssl/mysite.com/370952/server.crt;
    ssl_certificate_key /etc/nginx/ssl/mysite.com/370952/server.key;

    ssl_protocols TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    index index.html index.htm;

    charset utf-8;

    try_files $uri $uri/ /index.html;

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/mysite.com-error.log error;

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

然后我的构建过程是:

cd /home/forge/mysite.com/
npm install
ng build --prod --aot

我将mysite.com 配置为指向IP,在DNS 端,这里没有问题.

I configured my mysite.com to point on the IP, on DNS side, there is no problem here.

当我检查日志时,我有:

When I check the logs, I have:

2018/06/27 03:00:11 [error] 20122#20122: *8 directory index of "/home/forge/mysite.com/" is forbidden, client: 109.7.226.209, server: mysite.com, request: "GET / HTTP/2.0", host: "mysite.com"
2018/06/27 03:12:09 [error] 24560#24560: *25 directory index of "/home/forge/mysite.com/" is forbidden, client: 109.7.226.209, server: mysite.com, request: "GET / HTTP/2.0", host: "mysite.com"

但我从来没有摆脱过我的禁止错误......

But I never get rid of my Forbidden error...

知道吗???

推荐答案

构建后,您将拥有一个 dist 文件夹,其中将有您的项目构建.如果您的项目文件夹名称是 mysite,那么您的 nginx 配置中的根路径应该是 /home/forge/mysite.com/dist/my-site

After the build you are going to have a dist folder in which there will be your project build. If your project folder name is mysite so your root path inside your nginx config should be /home/forge/mysite.com/dist/my-site

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name mysite.com;
    root /home/forge/mysite.com/dist/mysite;
    ...
    ....

这篇关于在 Nginx 上部署 Angular 6 应用程序 - 禁止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆