Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure proxy_redirect for github pages hosted #125

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions config/nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ http {
default "public, max-age=0, s-maxage=31536000";
}

map $http_x_forwarded_proto $map_request_proto {
"https" "https";
default "http";
}

access_log <%= platform == 'heroku' ? 'logs/nginx/access.log' : '/dev/stdout' %> l2met;
error_log <%= platform == 'heroku' ? 'logs/nginx/access.log' : '/dev/stderr' %>;

Expand Down Expand Up @@ -139,35 +144,42 @@ http {

location /osaka04 {
include force_https.conf;
proxy_redirect https://rubykansai.github.io/osaka04 $map_request_proto://$http_host/osaka04;
proxy_pass https://rubykansai.github.io;
}

location /osaka03 {
include force_https.conf;
proxy_redirect https://rubykansai.github.io/osaka03 $map_request_proto://$http_host/osaka03;
proxy_pass https://rubykansai.github.io;
}

location ~ ^/osaka02(.*) {
proxy_redirect https://rubykansai.github.io/osaka02 $map_request_proto://$http_host/osaka02;
proxy_pass https://rubykansai.github.io;
}

location ~ ^/osaka01(.*) {
proxy_redirect https://rubykansai.github.io/osaka01 $map_request_proto://$http_host/osaka01;
proxy_pass https://rubykansai.github.io;
}

location /kansai08 {
include force_https.conf;
proxy_redirect https://rubykansai.github.io/kansai08 $map_request_proto://$http_host/kansai08;
proxy_pass https://rubykansai.github.io;
}

location ~ ^/kansai2017(.*) {
proxy_redirect https://rubykansai.github.io/kansai2017 $map_request_proto://$http_host/kansai2017;
proxy_pass https://rubykansai.github.io;
}

#
# kansai 06, y10y
#
location ~ ^/kansai06(.*) {
proxy_redirect https://rubykansai.github.io/kansai06 $map_request_proto://$http_host/kansai06;
proxy_pass https://rubykansai.github.io;
}

Expand All @@ -182,21 +194,25 @@ http {
# chuork 01, y6y
#
location ~ ^/chuork01(.*) {
proxy_redirect https://chuork.github.io/chuork01 $map_request_proto://$http_host/chuork01;
proxy_pass https://chuork.github.io;
}

#
# okrk01, y6y
#
location ~ ^/okrk01(.*) {
proxy_redirect https://ruby.okinawa/okrk01 $map_request_proto://$http_host/okrk01;
proxy_set_header Host "ruby.okinawa";
proxy_pass https://okinawarb.github.io;
}

#
# shibuya01, y6y
#
location ~ ^/shibuya01(.*) {
proxy_pass https://shibuyarb.github.io;
proxy_redirect https://shibuyarb.github.io/shibuya01 $map_request_proto://$http_host/shibuya01;
proxy_pass https://shibuyarb.github.io;
}

#
Expand All @@ -210,42 +226,48 @@ http {
# tokyu13, y6y
#
location ~ ^/tokyu13(.*) {
proxy_redirect https://tokyurubykaigi.github.io/tokyu13 $map_request_proto://$http_host/tokyu13;
proxy_pass https://tokyurubykaigi.github.io;
}

#
# tokyu12, y6y
#
location ~ ^/tokyu12(.*) {
proxy_redirect https://tokyurubykaigi.github.io/tokyu12 $map_request_proto://$http_host/tokyu12;
proxy_pass https://tokyurubykaigi.github.io;
}

#
# tokyu11, y6y
#
location ~ ^/tokyu11(.*) {
proxy_redirect https://tokyurubykaigi.github.io/tokyu11 $map_request_proto://$http_host/tokyu11;
proxy_pass https://tokyurubykaigi.github.io;
}

#
# tokyu09, y6y
#
location ~ ^/tokyu09(.*) {
proxy_redirect https://tokyurubykaigi.github.io/tokyu09 $map_request_proto://$http_host/tokyu09;
proxy_pass https://tokyurubykaigi.github.io;
}

#
# tokyu08, y6y
#
location ~ ^/tokyu08(.*) {
proxy_pass https://tokyurb.github.io;
proxy_redirect https://tokyurb.github.io/tokyu08 $map_request_proto://$http_host/tokyu08;
proxy_pass https://tokyurb.github.io;
}

#
# kanagawa01, y6y
#
location ~ ^/kana01(.*) {
proxy_pass https://kawasakirb.github.io;
proxy_redirect https://kawasakirb.github.io/kana01 $map_request_proto://$http_host/kana01;
proxy_pass https://kawasakirb.github.io;
}

location ~ ^/hamamatsu01(.*) {
Expand All @@ -262,24 +284,29 @@ http {

location ~ ^/oedo10(.*) {
include force_https.conf;
proxy_redirect https://asakusa.rubyist.net/oedo10 $map_request_proto://$http_host/oedo10;
proxy_set_header Host "asakusa.rubyist.net";
proxy_pass https://asakusarb.github.io;
}

location /tokyo12 {
include force_https.conf;
proxy_redirect https://tokyorubykaigi12.github.io/tokyo12 https://regional.rubykaigi.org/tokyo12;
proxy_redirect https://tokyorubykaigi12.github.io/tokyo12 $map_request_proto://$http_host/tokyo12;
proxy_pass https://tokyorubykaigi12.github.io;
}

location ~ ^/tokyo11(.*) {
proxy_redirect https://ko1.github.io/tokyo11 $map_request_proto://$http_host/tokyo11;
proxy_pass https://ko1.github.io;
}

location ~ ^/tokyu10(.*) {
proxy_redirect https://tokyurubykaigi.github.io/tokyu10 $map_request_proto://$http_host/tokyu10;
proxy_pass https://tokyurubykaigi.github.io;
}

location ~ ^/kwsk01(.*) {
proxy_redirect https://kawasakirb.github.io/kwsk01 $map_request_proto://$http_host/kwsk01;
proxy_pass https://kawasakirb.github.io;
}

Expand Down
78 changes: 49 additions & 29 deletions spec/regional_rubykaigi_org_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,52 +12,73 @@
%w(
/
/oedo03/
/osaka01/
/kansai2017/
/kansai06/
/kansai05/
/chuork01/
/shibuya01/
/tokyu12/
/tokyu11/
/tokyu09/
/tokyu08/
/kana01/
/oedo04/
/hamamatsu01/
/oedo05/
/oedo06/
/oedo10/
/tokyo12/
/tokyo11/
/tokyu10/
/kwsk01/
).each do |path|
describe(path) do
let(:res) { http_get("https://regional.rubykaigi.org#{path}") }
it "returns ok" do
pending 'kanrk05.herokuapp.com is down' if path == '/kansai05/'
pending 'http://rubykaigi-hamamatsu.s3-website-ap-northeast-1.amazonaws.com/hamamatsu01/ returns C-T:application/javascript' if path == '/hamamatsu01/'
pending 'asakusa.github.io returns 301 (#110)' if path == '/oedo10/'

expect(res.code).to eq("200")
expect(res["content-type"]).to include("text/html")
end
end
end

%w(
tokyo12
).each do |subdir|
describe("/#{subdir}") do
let(:res) { http_get("https://regional.rubykaigi.org/#{subdir}") }
it "may redirect to a path with trailing slash" do
case res.code
when "200"
expect(res["content-type"]).to include("text/html")
when /^3/
expect(res["location"]).to include("regional.rubykaigi.org/#{subdir}")
expect(res["location"]).not_to include("github.io/")

describe "GitHub Pages hosted subdirectories" do
%w(
tokyo12
osaka04
osaka03
osaka02
osaka01
kansai08
kansai2017
kansai06
chuork01
okrk01
shibuya01
tokyu13
tokyu12
tokyu11
tokyu09
tokyu08
kana01
oedo10
tokyo12
tokyo11
tokyu10
kwsk01
).each do |subdir|
describe(subdir) do
describe "/#{subdir}" do
let(:res) { http_get("https://regional.rubykaigi.org/#{subdir}") }
it "may redirect to a path with trailing slash" do
case res.code
when "200"
expect(res["content-type"]).to include("text/html")
when /^3/
expect(res["location"]).to include("regional.rubykaigi.org/#{subdir}/")
expect(res["location"]).not_to include("github.io/")
end
end
end

describe "/#{subdir}/" do
let(:res) { http_get("https://regional.rubykaigi.org/#{subdir}/") }
it "returns ok" do
#pending 'kanrk05.herokuapp.com is down' if path == '/kansai05/'
#pending 'http://rubykaigi-hamamatsu.s3-website-ap-northeast-1.amazonaws.com/hamamatsu01/ returns C-T:application/javascript' if path == '/hamamatsu01/'
#pending 'asakusa.github.io returns 301 (#110)' if path == '/oedo10/'
expect(res.code).to eq("200")
expect(res["content-type"]).to include("text/html")
end
end
end
end
Expand All @@ -68,7 +89,6 @@
/matsue08/ matsue.rubyist.net
/matrk07/ matsue.rubyist.net
/matsue07/ matsue.rubyist.net
/okrk01/ ruby.okinawa
).each_slice(2) do |path, host|
describe(path) do
let(:res) { http_get("https://regional.rubykaigi.org#{path}") }
Expand Down
Loading