-
-
Save stokito/fc5be8ac74be46f8d5daaa41e8279d58 to your computer and use it in GitHub Desktop.
Nginx config with CORS headers added and Basic Auth
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
server { | |
server_name example.com; | |
listen 443 ssl; | |
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; | |
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; | |
root /var/www/html; | |
access_log off; | |
location / { | |
if ($request_method = 'OPTIONS') { | |
add_header 'Access-Control-Allow-Origin' $http_origin; | |
add_header 'Access-Control-Allow-Credentials' 'true'; | |
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS'; | |
add_header 'Access-Control-Allow-Headers' 'Authorization,If-Modified-Since,Cache-Control,Content-Type'; | |
add_header 'Access-Control-Max-Age' 7200; | |
return 204; | |
} | |
proxy_pass http://127.0.0.1:8080; | |
auth_basic 'Realm'; | |
auth_basic_user_file /etc/nginx/.htpasswd; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment