简体   繁体   中英

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.

I followed AWS instruction to deploy my NodeJS app on 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. 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.

Here is an example of my html for one of the images:

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

在此处输入图片说明

I solved the problem. It turns out this is an AWS permission issue. Somehow all images uploaded to EC2 have

-rw------- 

permission. So I changed the permission to solve the 500 error.

chmod 744 my_logo.png

It's worth noting that only images uploaded to AWS have the above mod. Other files have the following mod which need not be changed

-rw-r--r-- 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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