Deploying Angular 6 app on Nginx - Forbidden

二次信任 提交于 2021-02-10 22:10:34

问题


I'm trying to deploy Angular app with 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;
    }
}

Then my process to build it is:

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

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...

Any idea???


回答1:


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;
    ...
    ....


来源:https://stackoverflow.com/questions/51057776/deploying-angular-6-app-on-nginx-forbidden

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!