Last active
March 11, 2020 08:52
-
-
Save greenpeas/d8f2c53ff2c878c943bab7ad3937ccf0 to your computer and use it in GitHub Desktop.
NGINX CORS
This file contains 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
server { | |
listen 80; | |
server_name mydomain.ru; | |
access_log /var/log/nginx/mydomain.ru.access.log; | |
error_log /var/log/nginx/mydomain.ru.error.log; | |
rewrite_log on; | |
# задаем красивую страницу 50x для пятисотых ошибок | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root /usr/share/nginx/html; | |
} | |
location / { | |
if ($request_method = 'OPTIONS') { | |
add_header 'Access-Control-Allow-Origin' '*'; | |
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; | |
add_header 'Access-Control-Allow-Headers' 'User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization'; | |
add_header 'Access-Control-Max-Age' 1728000; | |
add_header 'Content-Type' 'text/plain; charset=utf-8'; | |
add_header 'Content-Length' 0; | |
return 204; | |
} | |
add_header 'Access-Control-Allow-Origin' '*' always; | |
proxy_pass http://BACKEND_SERVER_ADDR:80; | |
include fastcgi_params; | |
fastcgi_param REMOTE_ADDR $http_x_real_ip; | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Host $remote_addr; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
proxy_read_timeout 300; | |
fastcgi_read_timeout 300; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment