Skip to content

Instantly share code, notes, and snippets.

@kkame
Last active August 11, 2019 05:11
Show Gist options
  • Save kkame/54e794ee868e753d95d27943c26f7d9c to your computer and use it in GitHub Desktop.
Save kkame/54e794ee868e753d95d27943c26f7d9c to your computer and use it in GitHub Desktop.
packagist-kr-nginx-config
upstream cluster {
server ncloud.packagist.kr fail_timeout=1s;
server packagist.jp backup;
keepalive 100;
}
server {
root /home/packagist-mirror/public;
# Add index.php to the list if you are using PHP
index index.htm index.html;
server_name packagist.kr *.packagist.kr;
add_header X-Where kt;
location / {
try_files $uri $uri/ =404;
}
location ~ \.json$ {
proxy_intercept_errors on;
gzip_static on;
recursive_error_pages on;
try_files $uri @prev;
}
location @prev{
root /home/packagist-mirror-pre/public;
gzip_static on;
recursive_error_pages on;
proxy_intercept_errors on;
error_page 404 = @after;
add_header X-Where kt-prev;
}
location @after{
root /home/packagist-mirror-backup/public;
gzip_static on;
recursive_error_pages on;
proxy_intercept_errors on;
error_page 404 = @proxy;
add_header X-Where kt-after;
}
location @proxy {
proxy_next_upstream error timeout invalid_header http_404;
proxy_pass http://cluster;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Host ncloud.packagist.kr;
proxy_redirect off;
proxy_http_version 1.1;
add_header X-Where proxy;
}
access_log /var/log/nginx/access.log main if=$log_ip;
error_log /var/log/nginx/packagist_error.log error;
listen [::]:443 ssl http2 ipv6only=on; # managed by Certbot
listen 443 http2 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/packagist.kr/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/packagist.kr/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 {
access_log /var/log/nginx/access.log main if=$log_ip;
if ($host = www.packagist.kr) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = packagist.kr) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 ;
listen [::]:80 ;
server_name packagist.kr *.packagist.kr;
add_header X-Where kt;
root /home/packagist-mirror/public;
# Add index.php to the list if you are using PHP
index index.htm index.html;
location / {
try_files $uri $uri/ =404;
}
location ~ \.json$ {
gzip_static on;
}
}
https://packagist.kr/kt.json
https://packagist.kr/kt-prev.json
https://packagist.kr/kt-after.json
https://packagist.kr/ncloud.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment