Apache2 CORS issue and solution / 아파치2 CORS 이슈와 해결책
Recently, I got a CORS error in nodejs project when I tried to load a file from webdav server (hosted by apache2 of ubuntu 18.04).
So, I have learned that server configuration on CORS makes this done.
As I googled with keywords ‘cors apache2’ and found that apache2.conf setting on <Directory> tag make things work.
<Directory /var/www/> | |
Options Indexes FollowSymLinks | |
AllowOverride None | |
Require all granted | |
Header always set Access-Control-Allow-Origin "*" | |
Header always set Access-Control-Allow-Headers "origin, content-type, cache-control, accept, authorization, if-match, destination, overwrite" | |
Header always set Access-Control-Expose-Headers "ETag" | |
Header always set Access-Control-Allow-Methods "GET, HEAD, POST, PUT, OPTIONS, MOVE, DELETE, COPY, LOCK, UNLOCK" | |
Header always set Access-Control-Allow-Credentials "true" | |
</Directory> |
If you got some errors like headers then you should enable headers as type following commands.
$ sudo a2enmod headers
$ sudo systemctl restart apache2
With these settings, CORS issues are gone for my nodejs project.
Have a nice day for visitors
-----------------------------------------------------------------------------
한국어 3줄요약
1. node앱에서 같은서버의 webdav에서 파일 가져오는게 안되서 확인해보니 CORS 위반이래
2. 그래서 apache2.conf 설정을 열고 Directory항목에 Header always...를 추가해주고, 아래 header추가하고 apache2서비스 재시작하니.
3. 아주 잘됨. 끝
Comments