Created
November 26, 2020 18:01
-
-
Save flufy3d/34afc88f0b796ec3a3408d14d97a3dfe to your computer and use it in GitHub Desktop.
nginx config for go http ,only add basic_auth for directory browse
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 { | |
server_name xxx.xxx.com; | |
location ~ ^/.*(json|gif|png|jpg|bundle|mvol|appx|appxbundle|apk)$ { | |
try_files $uri @main; | |
} | |
location ~ ^/apicall(/.*)$ { | |
#default_type text/html; | |
#return 200 $1?$query_string; | |
add_header Access-Control-Allow-Origin *; | |
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS'; | |
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,X-Access-Token'; | |
if ($request_method = 'OPTIONS') { | |
return 204; | |
} | |
proxy_pass http://127.0.0.1:9091$1?$query_string; | |
proxy_redirect off; | |
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-Proto $scheme; | |
client_max_body_size 0; # disable upload limit | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
} | |
location / { | |
auth_basic "Restricted"; | |
auth_basic_user_file /etc/nginx/file-htpasswd; | |
if ( $query_string != "") { | |
rewrite ^.*$ /apicall$uri last; | |
} | |
try_files $uri @main; | |
} | |
location @main { | |
add_header Access-Control-Allow-Origin *; | |
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS'; | |
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,X-Access-Token'; | |
if ($request_method = 'OPTIONS') { | |
return 204; | |
} | |
proxy_pass http://127.0.0.1:9091; | |
proxy_redirect off; | |
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-Proto $scheme; | |
client_max_body_size 0; # disable upload limit | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
} | |
listen [::]:443 ssl; # managed by Certbot | |
listen 443 ssl; # managed by Certbot | |
ssl_certificate /etc/letsencrypt/live/file.360.world/fullchain.pem; # managed by Certbot | |
ssl_certificate_key /etc/letsencrypt/live/file.360.world/privkey.pem; # managed by Certbot | |
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot | |
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot | |
} | |
server { | |
if ($host = xxx.xxx.com) { | |
return 301 https://$host$request_uri; | |
} # managed by Certbot | |
server_name xxx.xxx.com; | |
listen [::]:80; | |
listen 80; | |
return 404; # managed by Certbot | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment