Skip to content

Instantly share code, notes, and snippets.

@stokito
Forked from tomkersten/somehost.conf
Last active July 7, 2022 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stokito/fc5be8ac74be46f8d5daaa41e8279d58 to your computer and use it in GitHub Desktop.
Save stokito/fc5be8ac74be46f8d5daaa41e8279d58 to your computer and use it in GitHub Desktop.
Nginx config with CORS headers added and Basic Auth
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