Last active
August 27, 2024 13:00
-
-
Save revant/4baf8c4dadc9b6b28ff3d85bd049c066 to your computer and use it in GitHub Desktop.
Frappe CORS for nginx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| location / { | |
| rewrite ^(.+)/$ $1 permanent; | |
| rewrite ^(.+)/index\.html$ $1 permanent; | |
| rewrite ^(.+)\.html$ $1 permanent; | |
| # Allow CORS for static files | |
| add_header Access-Control-Allow-Origin $cors_origin; | |
| add_header Access-Control-Allow-Methods "GET, OPTIONS"; | |
| location ~* ^/files/.*.(htm|html|svg|xml) { | |
| add_header Content-disposition "attachment"; | |
| # Allow CORS again, specifically for the above filetypes | |
| add_header Access-Control-Allow-Origin $cors_origin; | |
| add_header Access-Control-Allow-Methods "GET, OPTIONS"; | |
| try_files /$site_name/public/$uri @webserver; | |
| } | |
| try_files /$site_name/public/$uri @webserver; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| location @webserver { | |
| if ($request_method = 'OPTIONS') { | |
| add_header 'Access-Control-Allow-Origin' '*'; | |
| add_header 'Access-Control-Allow-Credentials' 'true'; | |
| add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; | |
| add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; | |
| add_header 'Access-Control-Max-Age' 1728000; | |
| add_header 'Content-Type' 'text/plain charset=UTF-8'; | |
| add_header 'Content-Length' 0; | |
| return 204; | |
| } | |
| if ($request_method = 'POST') { | |
| add_header 'Access-Control-Allow-Origin' '*'; | |
| add_header 'Access-Control-Allow-Credentials' 'true'; | |
| add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; | |
| add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; | |
| } | |
| if ($request_method = 'GET') { | |
| add_header 'Access-Control-Allow-Origin' '*'; | |
| add_header 'Access-Control-Allow-Credentials' 'true'; | |
| add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; | |
| add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; | |
| } | |
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
| proxy_set_header X-Forwarded-Proto $scheme; | |
| proxy_set_header X-Frappe-Site-Name site1.local.com; | |
| proxy_set_header Host $host; | |
| proxy_set_header X-Use-X-Accel-Redirect True; | |
| proxy_read_timeout 120; | |
| proxy_redirect off; | |
| proxy_pass http://frappe-bench-frappe; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi
In the nginx config file, in the server level there are additional config files
Dont we have to chage any of these for the CORS config to allow access ?