Skip to content

Commit

Permalink
Separate nginx conf, add ubkg-api to DEV
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanzhou committed Jan 24, 2023
1 parent f56ac0a commit 263d090
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 141 deletions.
2 changes: 2 additions & 0 deletions docker-compose.development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ services:
- "7777:7777"
# spatial-api
- "8888:8888"
# HuBMAP ubkg-api
- "6666:6666"
volumes:
# Mount the VERSION file and BUILD file
- "./VERSION:/usr/src/app/VERSION"
Expand Down
50 changes: 50 additions & 0 deletions nginx/conf.d-dev/hubmap-ubkg-api.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# HuBMAP ubkg-api
# Port 6666 on host maps to 6666 on container
server {
# Only root can listen on ports below 1024, we use higher-numbered ports
# since nginx is running under non-root user hubmap
listen 6666;

server_name localhost;
root /usr/share/nginx/html;

# Logging to the mounted volume for outside container access
access_log /usr/src/app/log/nginx_access_hubmap-ubkg-api.log;
error_log /usr/src/app/log/nginx_error_hubmap-ubkg-api.log warn;

location / {
# Always enable CORS
# Response to preflight requests
if ($request_method = 'OPTIONS') {
# The directive `add_header` doesn't work when response status code is 401, 403 or 500
# The `always` parameter is specified so the header field will be added regardless of the response code
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, OPTIONS' always;

# Custom headers and headers various browsers should be OK with but aren't
add_header 'Access-Control-Allow-Headers' 'Authorization, Cache-Control, Content-Type' always;

# Cache the response to this preflight request in browser for 24 hours (86400 seconds)
# without sending another preflight request
add_header 'Access-Control-Max-Age' 86400 always;

add_header 'Content-Type' 'text/plain; charset=utf-8' always;
add_header 'Content-Length' 0 always;
return 204;
}

# Response to the original requests (HTTP methods are case-sensitive) with CORS enabled
if ($request_method ~ (POST|GET|PUT)) {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Authorization, Cache-Control, Content-Type' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
}

# Proxy reqeusts to the uWSGI server using the "uwsgi" protocol on port 5000 of the spatial-api container
include uwsgi_params;
uwsgi_pass uwsgi://hubmap-ubkg-api:5000;
}

}

90 changes: 0 additions & 90 deletions nginx/conf.d-dev/ubkg-api.conf

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,54 +1,3 @@
# HuBMAP ubkg-api
# Port 6666 on host maps to 6666 on container
server {
# Only root can listen on ports below 1024, we use higher-numbered ports
# since nginx is running under non-root user hubmap
listen 6666;

server_name localhost;
root /usr/share/nginx/html;

# Logging to the mounted volume for outside container access
access_log /usr/src/app/log/nginx_access_hubmap-ubkg-api.log;
error_log /usr/src/app/log/nginx_error_hubmap-ubkg-api.log warn;

location / {
# Always enable CORS
# Response to preflight requests
if ($request_method = 'OPTIONS') {
# The directive `add_header` doesn't work when response status code is 401, 403 or 500
# The `always` parameter is specified so the header field will be added regardless of the response code
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, OPTIONS' always;

# Custom headers and headers various browsers should be OK with but aren't
add_header 'Access-Control-Allow-Headers' 'Authorization, Cache-Control, Content-Type' always;

# Cache the response to this preflight request in browser for 24 hours (86400 seconds)
# without sending another preflight request
add_header 'Access-Control-Max-Age' 86400 always;

add_header 'Content-Type' 'text/plain; charset=utf-8' always;
add_header 'Content-Length' 0 always;
return 204;
}

# Response to the original requests (HTTP methods are case-sensitive) with CORS enabled
if ($request_method ~ (POST|GET|PUT)) {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Authorization, Cache-Control, Content-Type' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
}

# Proxy reqeusts to the uWSGI server using the "uwsgi" protocol on port 5000 of the spatial-api container
include uwsgi_params;
uwsgi_pass uwsgi://hubmap-ubkg-api:5000;
}

}


# Data Distillery ubkg-api
# Port 6667 on host maps to 6667 on container
server {
Expand Down
50 changes: 50 additions & 0 deletions nginx/conf.d-prod/hubmap-ubkg-api.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# HuBMAP ubkg-api
# Port 6666 on host maps to 6666 on container
server {
# Only root can listen on ports below 1024, we use higher-numbered ports
# since nginx is running under non-root user hubmap
listen 6666;

server_name localhost;
root /usr/share/nginx/html;

# Logging to the mounted volume for outside container access
access_log /usr/src/app/log/nginx_access_hubmap-ubkg-api.log;
error_log /usr/src/app/log/nginx_error_hubmap-ubkg-api.log warn;

location / {
# Always enable CORS
# Response to preflight requests
if ($request_method = 'OPTIONS') {
# The directive `add_header` doesn't work when response status code is 401, 403 or 500
# The `always` parameter is specified so the header field will be added regardless of the response code
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, OPTIONS' always;

# Custom headers and headers various browsers should be OK with but aren't
add_header 'Access-Control-Allow-Headers' 'Authorization, Cache-Control, Content-Type' always;

# Cache the response to this preflight request in browser for 24 hours (86400 seconds)
# without sending another preflight request
add_header 'Access-Control-Max-Age' 86400 always;

add_header 'Content-Type' 'text/plain; charset=utf-8' always;
add_header 'Content-Length' 0 always;
return 204;
}

# Response to the original requests (HTTP methods are case-sensitive) with CORS enabled
if ($request_method ~ (POST|GET|PUT)) {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Authorization, Cache-Control, Content-Type' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
}

# Proxy reqeusts to the uWSGI server using the "uwsgi" protocol on port 5000 of the spatial-api container
include uwsgi_params;
uwsgi_pass uwsgi://hubmap-ubkg-api:5000;
}

}

0 comments on commit 263d090

Please sign in to comment.