From 831d2dd30336d95e26ad2f51fafdf867d441bf82 Mon Sep 17 00:00:00 2001 From: Jon Andre Briones Date: Sun, 31 Aug 2025 00:31:38 -0700 Subject: [PATCH 1/3] Feature: Angular rewrite and subdomain migration closes #17 * Server block for `sfucsss.org` should serve the main Angular application * Added a redirect from `new` subdomain to the base domain * Disabled the `test` subdomain as it contains no new changes * Completed the server blocks for `madness` and `fall-hacks` * Disabled the "Under Construction" server block * Added redirects from the old URL schema from the main site to the subdomains: /events// -> .sfucsss.org/ * Subdomains will redirect to the `...//latest` directory for events URLs that don't specify a year --- nginx.conf | 344 ++++++++++++++++++++++++----------------------------- 1 file changed, 157 insertions(+), 187 deletions(-) diff --git a/nginx.conf b/nginx.conf index 5be5100..2d4df6f 100755 --- a/nginx.conf +++ b/nginx.conf @@ -2,172 +2,72 @@ upstream backend { server unix:/var/www/gunicorn.sock fail_timeout=0; } +# Redirect from the first rewrite to the Angular rewrite server { - server_name new.sfucsss.org; + server_name www.new.sfucsss.org new.sfucsss.org; listen 80; - - root /var/www/html; - - access_log /var/www/logs/csss-site-backend/nginx-access.log; - error_log /var/www/logs/csss-site-backend/nginx-error.log; - - # proxy csss-site-backend - location /api/ { - rewrite ^/api/(.*)$ /$1 break; - - keepalive_timeout 5; - client_max_body_size 1G; # Was 4G - - 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; - proxy_pass http://backend; - - add_header Access-Control-Allow-Origin https://new.sfucsss.org always; - add_header Access-Control-Allow-Credentials true; - } - - # redirects old 2024 mountain madness requests to the new URL - location ~ ^/events/2024/mm(/|/index.html)?$ { - return 301 /mountain_madness/2024/index.html; - } - - # any other matching path - location / { - charset utf-8; - try_files $uri $uri/ $uri/index.html =404; - } + return 301 $scheme://sfucsss.org$request_uri; } -# TODO: When redirecting sfucsss.org to the Angular rewrite, delete the other new.sfucsss.org block and uncomment this one. -# Redirect from the first rewrite to the Angular rewrite +# suitable for testing new deployments # server { -# server_name www.new.sfucsss.org new.sfucsss.org; +# server_name test.sfucsss.org; # listen 80; -# return 301 $scheme://sfucsss.org$request_uri; -# } - -# TODO: Uncomment me once the A record points to this VPS -# server { - # server_name test.sfucsss.org; - # listen 80; - # - # root /var/www/html; - # - # access_log /var/www/logs/csss-site-backend/nginx-access.log; - # error_log /var/www/logs/csss-site-backend/nginx-error.log; - # - # error_page 404 /404.html; - # - # # proxy csss-site-backend - # location /api/ { - # rewrite ^/api/(.*)$ /$1 break; - # - # keepalive_timeout 5; - # client_max_body_size 1G; # Was 4G - # - # 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; - # proxy_pass http://backend; - # - # # update cors header to allow requests from test site - # add_header Access-Control-Allow-Origin https://sfucsss.org always; - # add_header Access-Control-Allow-Credentials true; - # } - # - # # Events had a URL scheme like `sfucsss.org/events//[/page]` - # # We want to redirect them to `.sfucsss.org/[/page]` - # location ~ "^/events/(mm|mountain_madness)/(?\d{4})(?/.*)$" { - # return 301 https://madness.sfucsss.org/$year$page; - # } - # - # # Since they used underscores before, we'll need to redirect URLs to the hyphenated version - # location ~ "^/events/(?tech_fair|fall_hacks)/(?\d{4})(?/.*)?$" { - # set $new_event ""; - # if ($event = "tech_fair") { - # set $new_event "tech-fair"; - # } - # if ($event = "fall_hacks") { - # set $new_event "fall-hacks"; - # } - # return 301 /events/$new_event/$year$page; - # } - # - # # for the rest of the subdomains - # location ~ "^/events/(?frosh|tech-fair|fall-hacks)/(?\d{4})(?/.*)?$" { - # return 301 https://$event.sfucsss.org/$year$page; - # } - # - # # No 404 page since that will be handled by Angular - # location / { - # charset utf-8; - # try_files $uri $uri/ index.html; - # } +# +# root /var/www/test-sfucsss; +# +# access_log /var/www/logs/csss-site-backend/test-nginx-access.log; +# error_log /var/www/logs/csss-site-backend/test-nginx-error.log; +# +# error_page 404 /404.html; +# +# # proxy csss-site-backend +# location /api/ { +# rewrite ^/api/(.*)$ /$1 break; +# +# keepalive_timeout 5; +# client_max_body_size 1G; # Was 4G +# +# 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; +# proxy_pass http://backend; +# +# # update cors header to allow requests from test site +# add_header Access-Control-Allow-Origin https://test.sfucsss.org always; +# add_header Access-Control-Allow-Credentials true; +# } +# +# # Events had a URL scheme like `sfucsss.org/events//[/page]` +# # We want to redirect them to `.sfucsss.org/[/page]` +# location ~ "^/events/(mm|mountain_madness)/(?\d{4})(?/.*)$" { +# return 301 https://madness.sfucsss.org/$year$page; +# } +# +# # Since they used underscores before, we'll need to redirect URLs to the hyphenated version +# location ~ "^/events/(?tech-fair|fall-hacks)/(?\d{4})(?/.*)?$" { +# set $new_event ""; +# if ($event = "tech_fair") { +# set $new_event "tech-fair"; +# } +# if ($event = "fall_hacks") { +# set $new_event "fall-hacks"; +# } +# return 301 /events/$new_event/$year$page; +# } +# +# # for the rest of the subdomains +# location ~ "^/events/(?frosh|tech-fair|fall-hacks)/(?\d{4})(?/.*)?$" { +# return 301 https://$event.sfucsss.org/$year$page; +# } +# +# location / { +# charset utf-8; +# try_files $uri $uri/ $uri.html $uri/index.html =404; +# } # } -# serves the test version of the site -# suitable for testing new deployments -server { - server_name test.sfucsss.org; - listen 80; - - root /var/www/test-sfucsss; - - access_log /var/www/logs/csss-site-backend/test-nginx-access.log; - error_log /var/www/logs/csss-site-backend/test-nginx-error.log; - - error_page 404 /404.html; - - # proxy csss-site-backend - location /api/ { - rewrite ^/api/(.*)$ /$1 break; - - keepalive_timeout 5; - client_max_body_size 1G; # Was 4G - - 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; - proxy_pass http://backend; - - # update cors header to allow requests from test site - add_header Access-Control-Allow-Origin https://test.sfucsss.org always; - add_header Access-Control-Allow-Credentials true; - } - - # Events had a URL scheme like `sfucsss.org/events//[/page]` - # We want to redirect them to `.sfucsss.org/[/page]` - location ~ "^/events/(mm|mountain_madness)/(?\d{4})(?/.*)$" { - return 301 https://madness.sfucsss.org/$year$page; - } - - # Since they used underscores before, we'll need to redirect URLs to the hyphenated version - location ~ "^/events/(?tech_fair|fall_hacks)/(?\d{4})(?/.*)?$" { - set $new_event ""; - if ($event = "tech_fair") { - set $new_event "tech-fair"; - } - if ($event = "fall_hacks") { - set $new_event "fall-hacks"; - } - return 301 /events/$new_event/$year$page; - } - - # for the rest of the subdomains - location ~ "^/events/(?frosh|tech-fair|fall-hacks)/(?\d{4})(?/.*)?$" { - return 301 https://$event.sfucsss.org/$year$page; - } - - location / { - charset utf-8; - try_files $uri $uri/ index.html; - } -} - # TODO: Figure out how to do a wildcard domain # Serves the event pages # server { @@ -240,38 +140,51 @@ server { } location / { - # TODO: When the rest of the static pages are migrated, uncomment the next line - # root /var/www/html/frosh/latest; + root /var/www/html/tech-fair/latest; try_files $uri $uri/ /index.html =404; } } -# TODO: Uncomment this when Fall Hacks A record made -# server { -# server_name fall-hacks.sfucsss.org -# listen 80; -# -# root /var/www/html; -# -# location / { -# try_files /404.html =404; -# } -# } +server { + server_name fall-hacks.sfucsss.org + listen 80; -# TODO: Uncomment this when Madness A record made -# server { -# server_name madness.sfucsss.org -# listen 80; -# -# root /var/www/html; -# -# location / { -# try_files /404.html =404; -# } -# } + root /var/www/html/fall-hacks; + + location /static/ { + alias /var/www/html/static; + } + + location ~ "^/(?\d{4})(/.*)?$" { + try_files $uri $uri/ $year/index.html; + } + + location / { + root /var/www/html/fall-hacks/latest; + try_files $uri $uri/ /index.html =404; + } +} + +server { + server_name madness.sfucsss.org + listen 80; + + root /var/www/html/madness; + + location /static/ { + alias /var/www/html/static; + } + + location ~ "^/(?\d{4})(/.*)?$" { + try_files $uri $uri/ $year/index.html; + } + + location / { + root /var/www/html/madness/latest; + try_files $uri $uri/ /index.html =404; + } +} -# TODO: Comment this block out if there are no pages under construction. -# For pages under construction server { server_name www.sfucsss.org sfucsss.org; listen 80; @@ -281,12 +194,69 @@ server { access_log /var/www/logs/csss-site-backend/nginx-access.log; error_log /var/www/logs/csss-site-backend/nginx-error.log; - location ~* .(css|webp|png|svg) { - try_files $uri =404; + # proxy csss-site-backend + location /api/ { + rewrite ^/api/(.*)$ /$1 break; + + keepalive_timeout 5; + client_max_body_size 1G; # Was 4G + + 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; + proxy_pass http://backend; + + add_header Access-Control-Allow-Origin https://sfucsss.org always; + add_header Access-Control-Allow-Credentials true; + } + + # Events had a URL scheme like `sfucsss.org/events//[/page]` + # We want to redirect them to `.sfucsss.org/[/page]` + location ~ "^/events/(mm|mountain_madness)/(?\d{4})(?/.*)$" { + return 301 https://madness.sfucsss.org/$year$page; + } + + # Since they used underscores before, we'll need to redirect URLs to the hyphenated version + location ~ "^/events/(?tech_fair|fall-hacks)/(?\d{4})(?/.*)?$" { + set $new_event ""; + if ($event = "tech_fair") { + set $new_event "tech-fair"; + } + if ($event = "fall_hacks") { + set $new_event "fall-hacks"; + } + return 301 /events/$new_event/$year$page; + } + + # for the rest of the subdomains + location ~ "^/events/(?frosh|tech-fair|fall-hacks)/(?\d{4})(?/.*)?$" { + return 301 https://$event.sfucsss.org/$year$page; } location / { charset utf-8; - try_files /construction.html =503; + # Main site is a SPA, so we always serve the main Angular application + try_files $uri $uri/ $uri.html $uri/index.html; } } + +# For pages under construction +# server { +# server_name www.sfucsss.org sfucsss.org; +# listen 80; +# +# root /var/www/html; +# +# access_log /var/www/logs/csss-site-backend/nginx-access.log; +# error_log /var/www/logs/csss-site-backend/nginx-error.log; +# +# location ~* .(css|webp|png|svg) { +# try_files $uri =404; +# } +# +# location / { +# charset utf-8; +# try_files /construction.html =503; +# } +# } From a0bce4d8a329d79a308c62bf9dd0e63dae243ec5 Mon Sep 17 00:00:00 2001 From: Jon Andre Briones Date: Sun, 31 Aug 2025 09:35:21 -0700 Subject: [PATCH 2/3] Update: Main site --- frontend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend b/frontend index 39ebadf..a1c9887 160000 --- a/frontend +++ b/frontend @@ -1 +1 @@ -Subproject commit 39ebadf5b70af1e7c5d479de06d8a42133e339fb +Subproject commit a1c98871c4fd8a3aba6679b5e7b3bb5e35d1355d From 32dab363f339db131bd3bfbb0e9664dbe0491808 Mon Sep 17 00:00:00 2001 From: Jon Andre Briones Date: Sun, 31 Aug 2025 12:31:31 -0700 Subject: [PATCH 3/3] fix: missing semi-colon on fall-hacks server_name --- nginx.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nginx.conf b/nginx.conf index 2d4df6f..7e691c5 100755 --- a/nginx.conf +++ b/nginx.conf @@ -146,7 +146,7 @@ server { } server { - server_name fall-hacks.sfucsss.org + server_name fall-hacks.sfucsss.org; listen 80; root /var/www/html/fall-hacks;