简体   繁体   English

AWS EC2上的NodeJS:无法加载public / images文件夹

[英]NodeJS on AWS EC2: Cannot load public/images folder

I'm developing a NodeJS app and it looks good on my localhost so I decided to deploy it on AWS EC2. 我正在开发NodeJS应用程序,它在我的本地主机上看起来不错,因此我决定将其部署在AWS EC2上。

I followed AWS instruction to deploy my NodeJS app on AWS EC2. 我按照AWS的说明将自己的NodeJS应用程序部署在AWS EC2上。 When I started the server on EC2 by running node server.js, I found out that although javascript and css resources under public folder were loaded, all images from public/images were not loaded and the images folder was missing under Chrome developer tool > Sources. 当我通过运行node server.js在EC2上启动服务器时,我发现尽管公共文件夹下的javascript和CSS资源已加载,但公共/图像中的所有图像均未加载,并且在Chrome开发者工具>源下图像文件夹丢失了。 。 When running the app locally, all the images from public/images were loaded correctly. 在本地运行应用程序时,公共/图像中的所有图像均已正确加载。 There is also a 500 Internal server error on the Chrome console. Chrome控制台上还有500个内部服务器错误。

Here is an example of my html for one of the images: 这是其中一张图片的html示例:

<img src="public/images/my_logo.png"></img>

在此处输入图片说明

I solved the problem. 我解决了问题。 It turns out this is an AWS permission issue. 原来这是一个AWS权限问题。 Somehow all images uploaded to EC2 have 不知何故,所有上传到EC2的图像都有

-rw------- 

permission. 允许。 So I changed the permission to solve the 500 error. 因此,我更改了权限以解决500错误。

chmod 744 my_logo.png

It's worth noting that only images uploaded to AWS have the above mod. 值得注意的是,只有上传到AWS的图像具有上述mod。 Other files have the following mod which need not be changed 其他文件具有以下mod,无需更改

-rw-r--r-- 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM