我正在尝试使用Nginx部署Angular应用
这是我的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端,这里没有问题。
查看日志时,我有:
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"
但是我从来没有摆脱过我的禁忌错误...
任何想法?
答案 0 :(得分:2)
构建后,您将有一个 dist 文件夹,其中将有您的项目构建。如果您的项目文件夹名称为 mysite ,则您在nginx配置中的根路径应为/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;
...
....