[英]Nginx error when serving angular app on docker
I have built by angular app using ng build
我是使用ng build
角度应用程序
Now I cd
to the dist/iDot
folder and run 现在我cd
到dist/iDot
文件夹并运行
docker run -d -p 8080:80 -v $(pwd):/usr/share/nginx/html nginx:alpine
but when I access the url it shows nginx 403 Forbidden
error. 但是当我访问url时,它会显示nginx 403 Forbidden
错误。
I have chmod 777
dist folder and files and didn't seem to have any affect. 我有chmod 777
dist文件夹和文件,似乎没有任何影响。
Dist Folder Dist文件夹
garg10may@GCES15511:~/iDot/frontend/dist$ ls
iDot
garg10may@GCES15511:~/iDot/frontend/dist$ ls -ltrh iDot/
total 21M
-rwxrwxrwx 1 garg10may garg10may 49K May 3 18:02 main.js
-rwxrwxrwx 1 garg10may garg10may 284K May 3 18:02 es2015-polyfills.js
-rwxrwxrwx 1 garg10may garg10may 767K May 3 18:02 styles.js
-rwxrwxrwx 1 garg10may garg10may 6.1K May 3 18:02 runtime.js
-rwxrwxrwx 1 garg10may garg10may 236K May 3 18:02 polyfills.js
-rwxrwxrwx 1 garg10may garg10may 207K May 3 18:02 es2015-polyfills.js.map
-rwxrwxrwx 1 garg10may garg10may 8.9M May 3 18:02 vendor.js
-rwxrwxrwx 1 garg10may garg10may 28K May 3 18:02 main.js.map
-rwxrwxrwx 1 garg10may garg10may 6.1K May 3 18:02 runtime.js.map
-rwxrwxrwx 1 garg10may garg10may 235K May 3 18:02 polyfills.js.map
-rwxrwxrwx 1 garg10may garg10may 820K May 3 18:02 styles.js.map
-rwxrwxrwx 1 garg10may garg10may 9.4M May 3 18:02 vendor.js.map
-rwxrwxrwx 1 garg10may garg10may 829 May 3 18:02 index.html
-rwxrwxrwx 1 garg10may garg10may 5.4K May 3 18:02 favicon.ico
Container is running fine 集装箱运行正常
garg10may@GCES15511:~/iDot/frontend$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fcd8af3018e6 nginx:alpine "nginx -g 'daemon of…" 10 minutes ago Up 10 minutes 0.0.0.0:8080->80/tcp wonderful_shockley
5e1e49e7cc24 idot "java -Djava.securit…" 6 hours ago Up 6 hours 0.0.0.0:8081->8081/tcp idot
69a43bc460e1 mysql:5.7 "docker-entrypoint.s…" 6 hours ago Up 6 hours 3306/tcp, 33060/tcp idb
docker logs {container} docker logs {container}
2019/05/03 12:54:34 [error] 7#7: *1 directory index of "/usr/share/nginx/html/" is forbidden, client: 172.17.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost:8080"
172.17.0.1 - - [03/May/2019:12:54:34 +0000] "GET / HTTP/1.1" 403 556 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36" "-"
Try 1: 试试1:
garg10may@GCES15511:~/iDot/frontend/dist/iDot$ ls
es2015-polyfills.js favicon.ico main.js polyfills.js runtime.js styles.js vendor.js
es2015-polyfills.js.map index.html main.js.map polyfills.js.map runtime.js.map styles.js.map vendor.js.map
garg10may@GCES15511:~/iDot/frontend/dist/iDot$ cd ..
garg10may@GCES15511:~/iDot/frontend/dist$ docker run -d -p 8080:80 -v $(pwd)/iDot:/usr/share/nginx/html nginx:alpine
21910db703790152bf622ce01b2c814a224f1054e103e1d6b62c4b71fd47d542
garg10may@GCES15511:~/iDot/frontend/dist$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
21910db70379 nginx:alpine "nginx -g 'daemon of…" 3 seconds ago Up 1 second 0.0.0.0:8080->80/tcp ecstatic_germain
5e1e49e7cc24 idot "java -Djava.securit…" 7 hours ago Up 7 hours 0.0.0.0:8081->8081/tcp idot
69a43bc460e1 mysql:5.7 "docker-entrypoint.s…" 7 hours ago Up 7 hours 3306/tcp, 33060/tcp idb
garg10may@GCES15511:~/iDot/frontend/dist$ docker exec -it ecstatic_germain ls -l /usr/share/nginx/html/
total 0
drwxr-xr-x 2 root root 40 May 3 12:47 iDot
garg10may@GCES15511:~/iDot/frontend/dist$ docker exec -it ecstatic_germain ls -l /usr/share/nginx/html/iDot
total 0
garg10may@GCES15511:~/iDot/frontend/dist$
I think in the dist folder there will be another folder with the application name, you need to provide that folder on volume mapping to nginx image. 我认为在dist文件夹中会有另一个带有应用程序名称的文件夹,你需要在卷映射到nginx图像时提供该文件夹。 cd into your application name folder and run the same command, it will work cd进入你的应用程序名称文件夹并运行相同的命令,它将工作
Mount the iDot directory instead - 安装iDot目录 -
$ cd ~/iDot/frontend/dist
$ docker run -d -p 8080:80 -v $(pwd)/iDot:/usr/share/nginx/html nginx:alpine
You might be getting a 403 because nginx is unable to get an readable/executable index.html
file at the document root. 您可能会得到403,因为nginx无法在文档根目录下获取可读/可执行的index.html
文件。
For more information try doing a docker exec
into the container - 有关更多信息,请尝试将docker exec
放入容器中 -
$ docker exec -it 88c73dc32cad ls -l /usr/share/nginx/html/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.