From 9c18be042c3c8fb212eed749e98760636462a6d3 Mon Sep 17 00:00:00 2001 From: zxc8207 Date: Thu, 21 May 2020 11:57:35 +0800 Subject: [PATCH 01/14] add dockerfile --- Dockerfile.nginx | 2 ++ docker-compose.yml | 11 +++++++++++ 2 files changed, 13 insertions(+) create mode 100644 Dockerfile.nginx diff --git a/Dockerfile.nginx b/Dockerfile.nginx new file mode 100644 index 000000000..486c7dd73 --- /dev/null +++ b/Dockerfile.nginx @@ -0,0 +1,2 @@ +FROM nginx +COPY static-html-directory /usr/share/nginx/html diff --git a/docker-compose.yml b/docker-compose.yml index 037d87a5e..ab582ea81 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,6 +15,7 @@ services: depends_on: - postgresql - elasticsearch + - nginx elasticsearch: build: context: . @@ -33,9 +34,19 @@ services: - "127.0.0.1:5432:5432" volumes: - postgres-data:/var/lib/postgresql/data + nginx: + build: + context: . + dockerfile: Dockerfile.nginx + ports: + - "127.0.0.1:8080:80" + volumes: + - nginx-data:/etc/nginx/nginx.conf volumes: elasticsearch-data: driver: local postgres-data: driver: local + nginx-data: + driver: local From 5f8fd4d12a01b9d140e170498766aa067a2b9c52 Mon Sep 17 00:00:00 2001 From: zxc8207 Date: Thu, 21 May 2020 14:21:12 +0800 Subject: [PATCH 02/14] nginx now builds --- Dockerfile.nginx | 2 +- docker-compose.yml | 2 +- index.html | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 index.html diff --git a/Dockerfile.nginx b/Dockerfile.nginx index 486c7dd73..fe43e481f 100644 --- a/Dockerfile.nginx +++ b/Dockerfile.nginx @@ -1,2 +1,2 @@ FROM nginx -COPY static-html-directory /usr/share/nginx/html +COPY index.html /usr/share/nginx/html diff --git a/docker-compose.yml b/docker-compose.yml index ab582ea81..23a8cd91d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -41,7 +41,7 @@ services: ports: - "127.0.0.1:8080:80" volumes: - - nginx-data:/etc/nginx/nginx.conf + - nginx-data:/etc/nginx volumes: elasticsearch-data: diff --git a/index.html b/index.html new file mode 100644 index 000000000..7089c54a7 --- /dev/null +++ b/index.html @@ -0,0 +1,10 @@ + + + + This is the title of the webpage! + + +

This is an example paragraph. Anything in the body tag will appear on the page, just like this p tag and its contents.

+ + +@victor-yarema From 77e8d154e0a1b612db1767d8ea540f49da264e60 Mon Sep 17 00:00:00 2001 From: zxc8207 Date: Thu, 28 May 2020 17:33:45 +0800 Subject: [PATCH 03/14] . --- Dockerfile.nginx | 9 ++++++++- docker-compose.yml | 2 +- index.html | 10 ---------- 3 files changed, 9 insertions(+), 12 deletions(-) delete mode 100644 index.html diff --git a/Dockerfile.nginx b/Dockerfile.nginx index fe43e481f..0101b33fa 100644 --- a/Dockerfile.nginx +++ b/Dockerfile.nginx @@ -1,2 +1,9 @@ FROM nginx -COPY index.html /usr/share/nginx/html + +RUN rm /etc/nginx/conf.d/default.conf + +RUN rm /etc/nginx/conf.d/examplessl.conf + +COPY content /usr/share/nginx/html + +COPY conf /etc/nginx diff --git a/docker-compose.yml b/docker-compose.yml index 23a8cd91d..6c5947200 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -41,7 +41,7 @@ services: ports: - "127.0.0.1:8080:80" volumes: - - nginx-data:/etc/nginx + - ./nginx-data:/usr/local/etc/nginx volumes: elasticsearch-data: diff --git a/index.html b/index.html deleted file mode 100644 index 7089c54a7..000000000 --- a/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - This is the title of the webpage! - - -

This is an example paragraph. Anything in the body tag will appear on the page, just like this p tag and its contents.

- - -@victor-yarema From 8cc97601ff164b38003246ae417f041a61836cc8 Mon Sep 17 00:00:00 2001 From: zxc8207 Date: Fri, 29 May 2020 12:16:44 +0800 Subject: [PATCH 04/14] Edit dependencies so the nginx now depends on the app instead of the app depending on nginx --- Dockerfile.nginx | 27 ++++++++++++++++++-------- docker-compose.yml | 5 ++--- index.html | 18 ++++++++++++++++++ nginx.conf | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 11 deletions(-) create mode 100644 index.html create mode 100644 nginx.conf diff --git a/Dockerfile.nginx b/Dockerfile.nginx index 0101b33fa..f048861c3 100644 --- a/Dockerfile.nginx +++ b/Dockerfile.nginx @@ -1,9 +1,20 @@ +# Base image FROM nginx - -RUN rm /etc/nginx/conf.d/default.conf - -RUN rm /etc/nginx/conf.d/examplessl.conf - -COPY content /usr/share/nginx/html - -COPY conf /etc/nginx +# Install dependencies +RUN apt-get update -qq && apt-get -y install apache2-utils +# establish where Nginx should look for files +ENV RAILS_ROOT /var/www/safecastapi +# Set our working directory inside the image +WORKDIR $RAILS_ROOT +# create log directory +RUN mkdir log +# copy over static assets +COPY public public/ +# Copy Nginx config template +COPY docker/web/nginx.conf /tmp/docker.nginx +# substitute variable references in the Nginx config template for real values from the environment +# put the final config in its place +RUN envsubst '$RAILS_ROOT' < /tmp/docker.nginx > /etc/nginx/conf.d/default.conf +EXPOSE 80 +# Use the "exec" form of CMD so Nginx shuts down gracefully on SIGTERM (i.e. `docker stop`) +CMD [ "nginx", "-g", "daemon off;" ] diff --git a/docker-compose.yml b/docker-compose.yml index 6c5947200..e9e5075af 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,7 +15,6 @@ services: depends_on: - postgresql - elasticsearch - - nginx elasticsearch: build: context: . @@ -38,10 +37,10 @@ services: build: context: . dockerfile: Dockerfile.nginx + depends_on: + - app ports: - "127.0.0.1:8080:80" - volumes: - - ./nginx-data:/usr/local/etc/nginx volumes: elasticsearch-data: diff --git a/index.html b/index.html new file mode 100644 index 000000000..4d032ab7b --- /dev/null +++ b/index.html @@ -0,0 +1,18 @@ + +Site Maintenance + + +
+

We’ll be back soon!

+
+

Sorry for the inconvenience but we’re performing some maintenance at the moment. If you need to you can always contact us, otherwise we’ll be back online shortly!

+

— The Safecast Team

+
+
diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 000000000..d41108b9f --- /dev/null +++ b/nginx.conf @@ -0,0 +1,47 @@ +upstream rails_app { + server app:3000; +} +server { + # define your domain + server_name localhost; + # define the public application root + root $RAILS_ROOT/public; + index index.html; + # define where Nginx should write its logs + access_log $RAILS_ROOT/log/nginx.access.log; + error_log $RAILS_ROOT/log/nginx.error.log; + + # deny requests for files that should never be accessed + location ~ /\. { + deny all; + } + location ~* ^.+\.(rb|log)$ { + deny all; + } + + # serve static (compiled) assets directly if they exist (for rails production) + location ~ ^/(assets|images|javascripts|stylesheets|swfs|system)/ { + try_files $uri @rails; + access_log off; + gzip_static on; + # to serve pre-gzipped version + expires max; + add_header Cache-Control public; + + add_header Last-Modified ""; + add_header ETag ""; + break; + } + + # send non-static file requests to the app server + location / { + try_files $uri @rails; + } + location @rails { + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_pass http://rails_app; + } +} From b1e03910e5a12e8441dc27e6fe7f8f154da356e8 Mon Sep 17 00:00:00 2001 From: zxc8207 Date: Fri, 29 May 2020 12:22:26 +0800 Subject: [PATCH 05/14] edit path to configuration file --- Dockerfile.nginx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.nginx b/Dockerfile.nginx index f048861c3..19a92d596 100644 --- a/Dockerfile.nginx +++ b/Dockerfile.nginx @@ -11,7 +11,7 @@ RUN mkdir log # copy over static assets COPY public public/ # Copy Nginx config template -COPY docker/web/nginx.conf /tmp/docker.nginx +COPY nginx.conf /tmp/docker.nginx # substitute variable references in the Nginx config template for real values from the environment # put the final config in its place RUN envsubst '$RAILS_ROOT' < /tmp/docker.nginx > /etc/nginx/conf.d/default.conf From 3d2788485eeaa08e7fc1e8898d7c8ccade227e1a Mon Sep 17 00:00:00 2001 From: zxc8207 Date: Tue, 2 Jun 2020 14:15:46 +0800 Subject: [PATCH 06/14] remove copy pasted configuration code and add reference to dockerfile.nginx --- Dockerfile.nginx | 2 + nginx.conf | 166 +++++++++++++++++++++++++++++++++++------------ 2 files changed, 125 insertions(+), 43 deletions(-) diff --git a/Dockerfile.nginx b/Dockerfile.nginx index 19a92d596..e2e73636a 100644 --- a/Dockerfile.nginx +++ b/Dockerfile.nginx @@ -1,3 +1,5 @@ +#Reference: https://itnext.io/docker-rails-puma-nginx-postgres-999cd8866b18 + # Base image FROM nginx # Install dependencies diff --git a/nginx.conf b/nginx.conf index d41108b9f..73d8377d1 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,47 +1,127 @@ + +# For more information on configuration, see: +# * Official English Documentation: http://nginx.org/en/docs/ +# * Official Russian Documentation: http://nginx.org/ru/docs/ + +user nginx; +worker_processes auto; +error_log /var/log/nginx/error.log; +pid /var/run/nginx.pid; + +# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. +include /usr/share/nginx/modules/*.conf; + upstream rails_app { server app:3000; } -server { - # define your domain - server_name localhost; - # define the public application root - root $RAILS_ROOT/public; - index index.html; - # define where Nginx should write its logs - access_log $RAILS_ROOT/log/nginx.access.log; - error_log $RAILS_ROOT/log/nginx.error.log; - - # deny requests for files that should never be accessed - location ~ /\. { - deny all; - } - location ~* ^.+\.(rb|log)$ { - deny all; - } - - # serve static (compiled) assets directly if they exist (for rails production) - location ~ ^/(assets|images|javascripts|stylesheets|swfs|system)/ { - try_files $uri @rails; - access_log off; - gzip_static on; - # to serve pre-gzipped version - expires max; - add_header Cache-Control public; - - add_header Last-Modified ""; - add_header ETag ""; - break; - } - - # send non-static file requests to the app server - location / { - try_files $uri @rails; - } - location @rails { - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header Host $http_host; - proxy_redirect off; - proxy_pass http://rails_app; - } + +events { + worker_connections 1024; +} + +http { + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + # Load modular configuration files from the /etc/nginx/conf.d directory. + # See http://nginx.org/en/docs/ngx_core_module.html#include + # for more information. + include /etc/nginx/conf.d/*.conf; + + index index.html index.htm; + + server { + listen 80 ; + listen [::]:80 ; + server_name localhost; + root /usr/share/nginx/html; + + # Load configuration files for the default server block. + include /etc/nginx/default.d/*.conf; + + location / { + } + + # redirect server error pages to the static page /40x.html + # + error_page 404 /404.html; + location = /40x.html { + } + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + } + + # proxy the PHP scripts to Apache listening on 127.0.0.1:80 + # + #location ~ \.php$ { + # proxy_pass http://127.0.0.1; + #} + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + #location ~ \.php$ { + # root html; + # fastcgi_pass 127.0.0.1:9000; + # fastcgi_index index.php; + # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; + # include fastcgi_params; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} + } + +# Settings for a TLS enabled server. +# +# server { +# listen 443 ssl http2 ; +# listen [::]:443 ssl http2 ; +# server_name _; +# root /usr/share/nginx/html; +# +# ssl_certificate "/etc/pki/nginx/server.crt"; +# ssl_certificate_key "/etc/pki/nginx/private/server.key"; +# # It is *strongly* recommended to generate unique DH parameters +# # Generate them with: openssl dhparam -out /etc/pki/nginx/dhparams.pem 2048 +# #ssl_dhparam "/etc/pki/nginx/dhparams.pem"; +# ssl_session_cache shared:SSL:1m; +# ssl_session_timeout 10m; +# ssl_protocols TLSv1 TLSv1.1 TLSv1.2; +# ssl_ciphers HIGH:SEED:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!RSAPSK:!aDH:!aECDH:!EDH-DSS-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA:!SRP; +# ssl_prefer_server_ciphers on; +# +# # Load configuration files for the default server block. +# include /etc/nginx/default.d/*.conf; +# +# location / { +# } +# +# error_page 404 /404.html; +# location = /40x.html { +# } +# +# error_page 500 502 503 504 /50x.html; +# location = /50x.html { +# } +# } + } From c898b1ee7fd9f9e9027ccf494bad39fb8918ffd7 Mon Sep 17 00:00:00 2001 From: zxc8207 Date: Tue, 2 Jun 2020 14:21:24 +0800 Subject: [PATCH 07/14] reset nginx.conf --- nginx.conf | 3 --- 1 file changed, 3 deletions(-) diff --git a/nginx.conf b/nginx.conf index 73d8377d1..a844fef1e 100644 --- a/nginx.conf +++ b/nginx.conf @@ -11,9 +11,6 @@ pid /var/run/nginx.pid; # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; -upstream rails_app { - server app:3000; -} events { worker_connections 1024; From 712d11d835e8061fab2d09dfaeb828a98aded8ac Mon Sep 17 00:00:00 2001 From: zxc8207 Date: Sat, 6 Jun 2020 22:49:44 +0800 Subject: [PATCH 08/14] modify run server command to start nginx too when running run_dev_server --- bin/run_dev_server.bash | 2 +- nginx.conf | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/run_dev_server.bash b/bin/run_dev_server.bash index 9761d15aa..5842921ce 100755 --- a/bin/run_dev_server.bash +++ b/bin/run_dev_server.bash @@ -1,3 +1,3 @@ #!/usr/bin/env bash -docker-compose up app +docker-compose up app nginx diff --git a/nginx.conf b/nginx.conf index a844fef1e..0198fc60a 100644 --- a/nginx.conf +++ b/nginx.conf @@ -11,6 +11,9 @@ pid /var/run/nginx.pid; # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; +upstream railsapp { + server 127.0.0.1:3000; +} events { worker_connections 1024; From c4f41898f112d41e24955a314ad2cb2edbeb0c99 Mon Sep 17 00:00:00 2001 From: zxc8207 Date: Sun, 7 Jun 2020 04:32:18 +0800 Subject: [PATCH 09/14] change nginx.conf back to the one that will serve rails app --- Dockerfile.nginx | 2 +- nginx.conf | 170 +++++++++++++---------------------------------- 2 files changed, 47 insertions(+), 125 deletions(-) diff --git a/Dockerfile.nginx b/Dockerfile.nginx index e2e73636a..545c29d9a 100644 --- a/Dockerfile.nginx +++ b/Dockerfile.nginx @@ -1,4 +1,4 @@ -#Reference: https://itnext.io/docker-rails-puma-nginx-postgres-999cd8866b18 +#Modified from: https://itnext.io/docker-rails-puma-nginx-postgres-999cd8866b18 # Base image FROM nginx diff --git a/nginx.conf b/nginx.conf index 0198fc60a..c09dd6844 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,127 +1,49 @@ +#Modified from: https://itnext.io/docker-rails-puma-nginx-postgres-999cd8866b18 -# For more information on configuration, see: -# * Official English Documentation: http://nginx.org/en/docs/ -# * Official Russian Documentation: http://nginx.org/ru/docs/ - -user nginx; -worker_processes auto; -error_log /var/log/nginx/error.log; -pid /var/run/nginx.pid; - -# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. -include /usr/share/nginx/modules/*.conf; - -upstream railsapp { - server 127.0.0.1:3000; +upstream rails_app { + server app:3000; } - -events { - worker_connections 1024; -} - -http { - log_format main '$remote_addr - $remote_user [$time_local] "$request" ' - '$status $body_bytes_sent "$http_referer" ' - '"$http_user_agent" "$http_x_forwarded_for"'; - - access_log /var/log/nginx/access.log main; - - sendfile on; - tcp_nopush on; - tcp_nodelay on; - keepalive_timeout 65; - types_hash_max_size 2048; - - include /etc/nginx/mime.types; - default_type application/octet-stream; - - # Load modular configuration files from the /etc/nginx/conf.d directory. - # See http://nginx.org/en/docs/ngx_core_module.html#include - # for more information. - include /etc/nginx/conf.d/*.conf; - - index index.html index.htm; - - server { - listen 80 ; - listen [::]:80 ; - server_name localhost; - root /usr/share/nginx/html; - - # Load configuration files for the default server block. - include /etc/nginx/default.d/*.conf; - - location / { - } - - # redirect server error pages to the static page /40x.html - # - error_page 404 /404.html; - location = /40x.html { - } - - # redirect server error pages to the static page /50x.html - # - error_page 500 502 503 504 /50x.html; - location = /50x.html { - } - - # proxy the PHP scripts to Apache listening on 127.0.0.1:80 - # - #location ~ \.php$ { - # proxy_pass http://127.0.0.1; - #} - - # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 - # - #location ~ \.php$ { - # root html; - # fastcgi_pass 127.0.0.1:9000; - # fastcgi_index index.php; - # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; - # include fastcgi_params; - #} - - # deny access to .htaccess files, if Apache's document root - # concurs with nginx's one - # - #location ~ /\.ht { - # deny all; - #} - } - -# Settings for a TLS enabled server. -# -# server { -# listen 443 ssl http2 ; -# listen [::]:443 ssl http2 ; -# server_name _; -# root /usr/share/nginx/html; -# -# ssl_certificate "/etc/pki/nginx/server.crt"; -# ssl_certificate_key "/etc/pki/nginx/private/server.key"; -# # It is *strongly* recommended to generate unique DH parameters -# # Generate them with: openssl dhparam -out /etc/pki/nginx/dhparams.pem 2048 -# #ssl_dhparam "/etc/pki/nginx/dhparams.pem"; -# ssl_session_cache shared:SSL:1m; -# ssl_session_timeout 10m; -# ssl_protocols TLSv1 TLSv1.1 TLSv1.2; -# ssl_ciphers HIGH:SEED:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!RSAPSK:!aDH:!aECDH:!EDH-DSS-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA:!SRP; -# ssl_prefer_server_ciphers on; -# -# # Load configuration files for the default server block. -# include /etc/nginx/default.d/*.conf; -# -# location / { -# } -# -# error_page 404 /404.html; -# location = /40x.html { -# } -# -# error_page 500 502 503 504 /50x.html; -# location = /50x.html { -# } -# } - +server { + # define your domain + server_name localhost; + # define the public application root + root $RAILS_ROOT/public; + index index.html; + # define where Nginx should write its logs + access_log $RAILS_ROOT/log/nginx.access.log; + error_log $RAILS_ROOT/log/nginx.error.log; + + # deny requests for files that should never be accessed + location ~ /\. { + deny all; + } + location ~* ^.+\.(rb|log)$ { + deny all; + } + + # serve static (compiled) assets directly if they exist (for rails production) + location ~ ^/(assets|images|javascripts|stylesheets|swfs|system)/ { + try_files $uri @rails; + access_log off; + gzip_static on; + # to serve pre-gzipped version + expires max; + add_header Cache-Control public; + + add_header Last-Modified ""; + add_header ETag ""; + break; + } + + # send non-static file requests to the app server + location / { + try_files $uri @rails; + } + location @rails { + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_pass http://rails_app; + } } From c157dc0ec387a29b6694cf2be336d18e60ea7a30 Mon Sep 17 00:00:00 2001 From: zxc8207 Date: Thu, 18 Jun 2020 06:56:53 +0800 Subject: [PATCH 10/14] Moved the modified nginx configuration folder to the repository. --- Dockerfile.nginx | 21 ----- bin/run_shell.bash | 2 +- docker-compose.yml | 2 + nginx.conf | 49 ------------ nginx/conf.d/1_webapp.conf | 47 +++++++++++ nginx/conf.d/blockips.conf | 1 + nginx/conf.d/maintenance.conf | 5 ++ nginx/conf.d/maintenance.conf.bak | 5 ++ nginx/conf.d/proxy.conf | 1 + nginx/conf.d/proxy.conf.bak | 1 + nginx/conf.d/rate_limit.conf | 1 + nginx/conf.d/virtual.conf | 15 ++++ nginx/conf.d/web.conf | 1 + nginx/fastcgi.conf | 26 ++++++ nginx/fastcgi.conf.default | 26 ++++++ nginx/fastcgi_params | 25 ++++++ nginx/fastcgi_params.default | 25 ++++++ nginx/html/index.html | 9 +++ nginx/koi-utf | 109 ++++++++++++++++++++++++++ nginx/koi-win | 103 ++++++++++++++++++++++++ nginx/mime.types | 97 +++++++++++++++++++++++ nginx/mime.types.default | 97 +++++++++++++++++++++++ nginx/nginx.conf | 122 +++++++++++++++++++++++++++++ nginx/nginx.conf.default | 117 +++++++++++++++++++++++++++ nginx/scgi_params | 17 ++++ nginx/scgi_params.default | 17 ++++ nginx/uwsgi_params | 17 ++++ nginx/uwsgi_params.default | 17 ++++ nginx/win-utf | 126 ++++++++++++++++++++++++++++++ 29 files changed, 1030 insertions(+), 71 deletions(-) delete mode 100644 nginx.conf create mode 100644 nginx/conf.d/1_webapp.conf create mode 100644 nginx/conf.d/blockips.conf create mode 100644 nginx/conf.d/maintenance.conf create mode 100644 nginx/conf.d/maintenance.conf.bak create mode 100644 nginx/conf.d/proxy.conf create mode 100644 nginx/conf.d/proxy.conf.bak create mode 100644 nginx/conf.d/rate_limit.conf create mode 100644 nginx/conf.d/virtual.conf create mode 100644 nginx/conf.d/web.conf create mode 100644 nginx/fastcgi.conf create mode 100644 nginx/fastcgi.conf.default create mode 100644 nginx/fastcgi_params create mode 100644 nginx/fastcgi_params.default create mode 100644 nginx/html/index.html create mode 100644 nginx/koi-utf create mode 100644 nginx/koi-win create mode 100644 nginx/mime.types create mode 100644 nginx/mime.types.default create mode 100644 nginx/nginx.conf create mode 100644 nginx/nginx.conf.default create mode 100644 nginx/scgi_params create mode 100644 nginx/scgi_params.default create mode 100644 nginx/uwsgi_params create mode 100644 nginx/uwsgi_params.default create mode 100644 nginx/win-utf diff --git a/Dockerfile.nginx b/Dockerfile.nginx index 545c29d9a..8bd0a7f15 100644 --- a/Dockerfile.nginx +++ b/Dockerfile.nginx @@ -1,22 +1 @@ -#Modified from: https://itnext.io/docker-rails-puma-nginx-postgres-999cd8866b18 - -# Base image FROM nginx -# Install dependencies -RUN apt-get update -qq && apt-get -y install apache2-utils -# establish where Nginx should look for files -ENV RAILS_ROOT /var/www/safecastapi -# Set our working directory inside the image -WORKDIR $RAILS_ROOT -# create log directory -RUN mkdir log -# copy over static assets -COPY public public/ -# Copy Nginx config template -COPY nginx.conf /tmp/docker.nginx -# substitute variable references in the Nginx config template for real values from the environment -# put the final config in its place -RUN envsubst '$RAILS_ROOT' < /tmp/docker.nginx > /etc/nginx/conf.d/default.conf -EXPOSE 80 -# Use the "exec" form of CMD so Nginx shuts down gracefully on SIGTERM (i.e. `docker stop`) -CMD [ "nginx", "-g", "daemon off;" ] diff --git a/bin/run_shell.bash b/bin/run_shell.bash index 5ee8a505c..45d565952 100755 --- a/bin/run_shell.bash +++ b/bin/run_shell.bash @@ -1,3 +1,3 @@ #!/usr/bin/env bash -docker-compose run --rm --service-ports --entrypoint /bin/bash app +docker-compose run --rm --service-ports --entrypoint /bin/bash nginx diff --git a/docker-compose.yml b/docker-compose.yml index e9e5075af..8a7aa217c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -41,6 +41,8 @@ services: - app ports: - "127.0.0.1:8080:80" + volumes: + - ./nginx/:/etc/nginx/ volumes: elasticsearch-data: diff --git a/nginx.conf b/nginx.conf deleted file mode 100644 index c09dd6844..000000000 --- a/nginx.conf +++ /dev/null @@ -1,49 +0,0 @@ -#Modified from: https://itnext.io/docker-rails-puma-nginx-postgres-999cd8866b18 - -upstream rails_app { - server app:3000; -} -server { - # define your domain - server_name localhost; - # define the public application root - root $RAILS_ROOT/public; - index index.html; - # define where Nginx should write its logs - access_log $RAILS_ROOT/log/nginx.access.log; - error_log $RAILS_ROOT/log/nginx.error.log; - - # deny requests for files that should never be accessed - location ~ /\. { - deny all; - } - location ~* ^.+\.(rb|log)$ { - deny all; - } - - # serve static (compiled) assets directly if they exist (for rails production) - location ~ ^/(assets|images|javascripts|stylesheets|swfs|system)/ { - try_files $uri @rails; - access_log off; - gzip_static on; - # to serve pre-gzipped version - expires max; - add_header Cache-Control public; - - add_header Last-Modified ""; - add_header ETag ""; - break; - } - - # send non-static file requests to the app server - location / { - try_files $uri @rails; - } - location @rails { - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header Host $http_host; - proxy_redirect off; - proxy_pass http://rails_app; - } -} diff --git a/nginx/conf.d/1_webapp.conf b/nginx/conf.d/1_webapp.conf new file mode 100644 index 000000000..8d81e6e19 --- /dev/null +++ b/nginx/conf.d/1_webapp.conf @@ -0,0 +1,47 @@ +#Modified from: https://itnext.io/docker-rails-puma-nginx-postgres-999cd8866b18 + +upstream safecastapi { + server app:3000; +} + +limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s; + +server{ + server_name safecastapi; + # define the public application root + root /var/www/safecastapi/public; + index index.html; + # deny requests for files that should never be accessed + location ~ /\. { + deny all; + } + location ~* ^.+\.(rb|log)$ { + deny all; + } + + # serve static (compiled) assets directly if they exist (for rails production) + location ~ ^/(assets|images|javascripts|stylesheets|swfs|system)/ { + try_files $uri @rails; + access_log off; + gzip_static on; + # to serve pre-gzipped version + expires max; + add_header Cache-Control public; + + add_header Last-Modified ""; + add_header ETag ""; + break; + } + + location / { + limit_req zone=one; + try_files $uri @rails; + } + location @rails { + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_pass http://safecastapi; + } +} diff --git a/nginx/conf.d/blockips.conf b/nginx/conf.d/blockips.conf new file mode 100644 index 000000000..60b7a16a6 --- /dev/null +++ b/nginx/conf.d/blockips.conf @@ -0,0 +1 @@ +#deny 192.168.176.1; diff --git a/nginx/conf.d/maintenance.conf b/nginx/conf.d/maintenance.conf new file mode 100644 index 000000000..1a53a8934 --- /dev/null +++ b/nginx/conf.d/maintenance.conf @@ -0,0 +1,5 @@ +server { + listen 81; + server_name _ localhost; + root /var/app/current/public/maintenance; +} diff --git a/nginx/conf.d/maintenance.conf.bak b/nginx/conf.d/maintenance.conf.bak new file mode 100644 index 000000000..1a53a8934 --- /dev/null +++ b/nginx/conf.d/maintenance.conf.bak @@ -0,0 +1,5 @@ +server { + listen 81; + server_name _ localhost; + root /var/app/current/public/maintenance; +} diff --git a/nginx/conf.d/proxy.conf b/nginx/conf.d/proxy.conf new file mode 100644 index 000000000..67d42ded2 --- /dev/null +++ b/nginx/conf.d/proxy.conf @@ -0,0 +1 @@ +client_max_body_size 10M; diff --git a/nginx/conf.d/proxy.conf.bak b/nginx/conf.d/proxy.conf.bak new file mode 100644 index 000000000..67d42ded2 --- /dev/null +++ b/nginx/conf.d/proxy.conf.bak @@ -0,0 +1 @@ +client_max_body_size 10M; diff --git a/nginx/conf.d/rate_limit.conf b/nginx/conf.d/rate_limit.conf new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/nginx/conf.d/rate_limit.conf @@ -0,0 +1 @@ + diff --git a/nginx/conf.d/virtual.conf b/nginx/conf.d/virtual.conf new file mode 100644 index 000000000..479ff5eb3 --- /dev/null +++ b/nginx/conf.d/virtual.conf @@ -0,0 +1,15 @@ +# +# A virtual host using mix of IP-, name-, and port-based configuration +# + +#server { +# listen 8000; +# listen somename:8080; +# server_name somename alias another.alias; + +# location / { +# root html; +# index index.html index.htm; +# } +#} + diff --git a/nginx/conf.d/web.conf b/nginx/conf.d/web.conf new file mode 100644 index 000000000..4362b900e --- /dev/null +++ b/nginx/conf.d/web.conf @@ -0,0 +1 @@ +proxy_read_timeout 600s; diff --git a/nginx/fastcgi.conf b/nginx/fastcgi.conf new file mode 100644 index 000000000..091738c60 --- /dev/null +++ b/nginx/fastcgi.conf @@ -0,0 +1,26 @@ + +fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; +fastcgi_param QUERY_STRING $query_string; +fastcgi_param REQUEST_METHOD $request_method; +fastcgi_param CONTENT_TYPE $content_type; +fastcgi_param CONTENT_LENGTH $content_length; + +fastcgi_param SCRIPT_NAME $fastcgi_script_name; +fastcgi_param REQUEST_URI $request_uri; +fastcgi_param DOCUMENT_URI $document_uri; +fastcgi_param DOCUMENT_ROOT $document_root; +fastcgi_param SERVER_PROTOCOL $server_protocol; +fastcgi_param REQUEST_SCHEME $scheme; +fastcgi_param HTTPS $https if_not_empty; + +fastcgi_param GATEWAY_INTERFACE CGI/1.1; +fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; + +fastcgi_param REMOTE_ADDR $remote_addr; +fastcgi_param REMOTE_PORT $remote_port; +fastcgi_param SERVER_ADDR $server_addr; +fastcgi_param SERVER_PORT $server_port; +fastcgi_param SERVER_NAME $server_name; + +# PHP only, required if PHP was built with --enable-force-cgi-redirect +fastcgi_param REDIRECT_STATUS 200; diff --git a/nginx/fastcgi.conf.default b/nginx/fastcgi.conf.default new file mode 100644 index 000000000..091738c60 --- /dev/null +++ b/nginx/fastcgi.conf.default @@ -0,0 +1,26 @@ + +fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; +fastcgi_param QUERY_STRING $query_string; +fastcgi_param REQUEST_METHOD $request_method; +fastcgi_param CONTENT_TYPE $content_type; +fastcgi_param CONTENT_LENGTH $content_length; + +fastcgi_param SCRIPT_NAME $fastcgi_script_name; +fastcgi_param REQUEST_URI $request_uri; +fastcgi_param DOCUMENT_URI $document_uri; +fastcgi_param DOCUMENT_ROOT $document_root; +fastcgi_param SERVER_PROTOCOL $server_protocol; +fastcgi_param REQUEST_SCHEME $scheme; +fastcgi_param HTTPS $https if_not_empty; + +fastcgi_param GATEWAY_INTERFACE CGI/1.1; +fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; + +fastcgi_param REMOTE_ADDR $remote_addr; +fastcgi_param REMOTE_PORT $remote_port; +fastcgi_param SERVER_ADDR $server_addr; +fastcgi_param SERVER_PORT $server_port; +fastcgi_param SERVER_NAME $server_name; + +# PHP only, required if PHP was built with --enable-force-cgi-redirect +fastcgi_param REDIRECT_STATUS 200; diff --git a/nginx/fastcgi_params b/nginx/fastcgi_params new file mode 100644 index 000000000..28decb955 --- /dev/null +++ b/nginx/fastcgi_params @@ -0,0 +1,25 @@ + +fastcgi_param QUERY_STRING $query_string; +fastcgi_param REQUEST_METHOD $request_method; +fastcgi_param CONTENT_TYPE $content_type; +fastcgi_param CONTENT_LENGTH $content_length; + +fastcgi_param SCRIPT_NAME $fastcgi_script_name; +fastcgi_param REQUEST_URI $request_uri; +fastcgi_param DOCUMENT_URI $document_uri; +fastcgi_param DOCUMENT_ROOT $document_root; +fastcgi_param SERVER_PROTOCOL $server_protocol; +fastcgi_param REQUEST_SCHEME $scheme; +fastcgi_param HTTPS $https if_not_empty; + +fastcgi_param GATEWAY_INTERFACE CGI/1.1; +fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; + +fastcgi_param REMOTE_ADDR $remote_addr; +fastcgi_param REMOTE_PORT $remote_port; +fastcgi_param SERVER_ADDR $server_addr; +fastcgi_param SERVER_PORT $server_port; +fastcgi_param SERVER_NAME $server_name; + +# PHP only, required if PHP was built with --enable-force-cgi-redirect +fastcgi_param REDIRECT_STATUS 200; diff --git a/nginx/fastcgi_params.default b/nginx/fastcgi_params.default new file mode 100644 index 000000000..28decb955 --- /dev/null +++ b/nginx/fastcgi_params.default @@ -0,0 +1,25 @@ + +fastcgi_param QUERY_STRING $query_string; +fastcgi_param REQUEST_METHOD $request_method; +fastcgi_param CONTENT_TYPE $content_type; +fastcgi_param CONTENT_LENGTH $content_length; + +fastcgi_param SCRIPT_NAME $fastcgi_script_name; +fastcgi_param REQUEST_URI $request_uri; +fastcgi_param DOCUMENT_URI $document_uri; +fastcgi_param DOCUMENT_ROOT $document_root; +fastcgi_param SERVER_PROTOCOL $server_protocol; +fastcgi_param REQUEST_SCHEME $scheme; +fastcgi_param HTTPS $https if_not_empty; + +fastcgi_param GATEWAY_INTERFACE CGI/1.1; +fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; + +fastcgi_param REMOTE_ADDR $remote_addr; +fastcgi_param REMOTE_PORT $remote_port; +fastcgi_param SERVER_ADDR $server_addr; +fastcgi_param SERVER_PORT $server_port; +fastcgi_param SERVER_NAME $server_name; + +# PHP only, required if PHP was built with --enable-force-cgi-redirect +fastcgi_param REDIRECT_STATUS 200; diff --git a/nginx/html/index.html b/nginx/html/index.html new file mode 100644 index 000000000..c5e11bd9e --- /dev/null +++ b/nginx/html/index.html @@ -0,0 +1,9 @@ + + + + This is the title of the webpage! + + +

This is an example paragraph. Anything in the body tag will appear on the page, just like this p tag and its contents.

+ + diff --git a/nginx/koi-utf b/nginx/koi-utf new file mode 100644 index 000000000..e7974ff6a --- /dev/null +++ b/nginx/koi-utf @@ -0,0 +1,109 @@ + +# This map is not a full koi8-r <> utf8 map: it does not contain +# box-drawing and some other characters. Besides this map contains +# several koi8-u and Byelorussian letters which are not in koi8-r. +# If you need a full and standard map, use contrib/unicode2nginx/koi-utf +# map instead. + +charset_map koi8-r utf-8 { + + 80 E282AC ; # euro + + 95 E280A2 ; # bullet + + 9A C2A0 ; #   + + 9E C2B7 ; # · + + A3 D191 ; # small yo + A4 D194 ; # small Ukrainian ye + + A6 D196 ; # small Ukrainian i + A7 D197 ; # small Ukrainian yi + + AD D291 ; # small Ukrainian soft g + AE D19E ; # small Byelorussian short u + + B0 C2B0 ; # ° + + B3 D081 ; # capital YO + B4 D084 ; # capital Ukrainian YE + + B6 D086 ; # capital Ukrainian I + B7 D087 ; # capital Ukrainian YI + + B9 E28496 ; # numero sign + + BD D290 ; # capital Ukrainian soft G + BE D18E ; # capital Byelorussian short U + + BF C2A9 ; # (C) + + C0 D18E ; # small yu + C1 D0B0 ; # small a + C2 D0B1 ; # small b + C3 D186 ; # small ts + C4 D0B4 ; # small d + C5 D0B5 ; # small ye + C6 D184 ; # small f + C7 D0B3 ; # small g + C8 D185 ; # small kh + C9 D0B8 ; # small i + CA D0B9 ; # small j + CB D0BA ; # small k + CC D0BB ; # small l + CD D0BC ; # small m + CE D0BD ; # small n + CF D0BE ; # small o + + D0 D0BF ; # small p + D1 D18F ; # small ya + D2 D180 ; # small r + D3 D181 ; # small s + D4 D182 ; # small t + D5 D183 ; # small u + D6 D0B6 ; # small zh + D7 D0B2 ; # small v + D8 D18C ; # small soft sign + D9 D18B ; # small y + DA D0B7 ; # small z + DB D188 ; # small sh + DC D18D ; # small e + DD D189 ; # small shch + DE D187 ; # small ch + DF D18A ; # small hard sign + + E0 D0AE ; # capital YU + E1 D090 ; # capital A + E2 D091 ; # capital B + E3 D0A6 ; # capital TS + E4 D094 ; # capital D + E5 D095 ; # capital YE + E6 D0A4 ; # capital F + E7 D093 ; # capital G + E8 D0A5 ; # capital KH + E9 D098 ; # capital I + EA D099 ; # capital J + EB D09A ; # capital K + EC D09B ; # capital L + ED D09C ; # capital M + EE D09D ; # capital N + EF D09E ; # capital O + + F0 D09F ; # capital P + F1 D0AF ; # capital YA + F2 D0A0 ; # capital R + F3 D0A1 ; # capital S + F4 D0A2 ; # capital T + F5 D0A3 ; # capital U + F6 D096 ; # capital ZH + F7 D092 ; # capital V + F8 D0AC ; # capital soft sign + F9 D0AB ; # capital Y + FA D097 ; # capital Z + FB D0A8 ; # capital SH + FC D0AD ; # capital E + FD D0A9 ; # capital SHCH + FE D0A7 ; # capital CH + FF D0AA ; # capital hard sign +} diff --git a/nginx/koi-win b/nginx/koi-win new file mode 100644 index 000000000..72afabe89 --- /dev/null +++ b/nginx/koi-win @@ -0,0 +1,103 @@ + +charset_map koi8-r windows-1251 { + + 80 88 ; # euro + + 95 95 ; # bullet + + 9A A0 ; #   + + 9E B7 ; # · + + A3 B8 ; # small yo + A4 BA ; # small Ukrainian ye + + A6 B3 ; # small Ukrainian i + A7 BF ; # small Ukrainian yi + + AD B4 ; # small Ukrainian soft g + AE A2 ; # small Byelorussian short u + + B0 B0 ; # ° + + B3 A8 ; # capital YO + B4 AA ; # capital Ukrainian YE + + B6 B2 ; # capital Ukrainian I + B7 AF ; # capital Ukrainian YI + + B9 B9 ; # numero sign + + BD A5 ; # capital Ukrainian soft G + BE A1 ; # capital Byelorussian short U + + BF A9 ; # (C) + + C0 FE ; # small yu + C1 E0 ; # small a + C2 E1 ; # small b + C3 F6 ; # small ts + C4 E4 ; # small d + C5 E5 ; # small ye + C6 F4 ; # small f + C7 E3 ; # small g + C8 F5 ; # small kh + C9 E8 ; # small i + CA E9 ; # small j + CB EA ; # small k + CC EB ; # small l + CD EC ; # small m + CE ED ; # small n + CF EE ; # small o + + D0 EF ; # small p + D1 FF ; # small ya + D2 F0 ; # small r + D3 F1 ; # small s + D4 F2 ; # small t + D5 F3 ; # small u + D6 E6 ; # small zh + D7 E2 ; # small v + D8 FC ; # small soft sign + D9 FB ; # small y + DA E7 ; # small z + DB F8 ; # small sh + DC FD ; # small e + DD F9 ; # small shch + DE F7 ; # small ch + DF FA ; # small hard sign + + E0 DE ; # capital YU + E1 C0 ; # capital A + E2 C1 ; # capital B + E3 D6 ; # capital TS + E4 C4 ; # capital D + E5 C5 ; # capital YE + E6 D4 ; # capital F + E7 C3 ; # capital G + E8 D5 ; # capital KH + E9 C8 ; # capital I + EA C9 ; # capital J + EB CA ; # capital K + EC CB ; # capital L + ED CC ; # capital M + EE CD ; # capital N + EF CE ; # capital O + + F0 CF ; # capital P + F1 DF ; # capital YA + F2 D0 ; # capital R + F3 D1 ; # capital S + F4 D2 ; # capital T + F5 D3 ; # capital U + F6 C6 ; # capital ZH + F7 C2 ; # capital V + F8 DC ; # capital soft sign + F9 DB ; # capital Y + FA C7 ; # capital Z + FB D8 ; # capital SH + FC DD ; # capital E + FD D9 ; # capital SHCH + FE D7 ; # capital CH + FF DA ; # capital hard sign +} diff --git a/nginx/mime.types b/nginx/mime.types new file mode 100644 index 000000000..296125695 --- /dev/null +++ b/nginx/mime.types @@ -0,0 +1,97 @@ + +types { + text/html html htm shtml; + text/css css; + text/xml xml; + image/gif gif; + image/jpeg jpeg jpg; + application/javascript js; + application/atom+xml atom; + application/rss+xml rss; + + text/mathml mml; + text/plain txt; + text/vnd.sun.j2me.app-descriptor jad; + text/vnd.wap.wml wml; + text/x-component htc; + + image/png png; + image/svg+xml svg svgz; + image/tiff tif tiff; + image/vnd.wap.wbmp wbmp; + image/webp webp; + image/x-icon ico; + image/x-jng jng; + image/x-ms-bmp bmp; + + font/woff woff; + font/woff2 woff2; + + application/java-archive jar war ear; + application/json json; + application/mac-binhex40 hqx; + application/msword doc; + application/pdf pdf; + application/postscript ps eps ai; + application/rtf rtf; + application/vnd.apple.mpegurl m3u8; + application/vnd.google-earth.kml+xml kml; + application/vnd.google-earth.kmz kmz; + application/vnd.ms-excel xls; + application/vnd.ms-fontobject eot; + application/vnd.ms-powerpoint ppt; + application/vnd.oasis.opendocument.graphics odg; + application/vnd.oasis.opendocument.presentation odp; + application/vnd.oasis.opendocument.spreadsheet ods; + application/vnd.oasis.opendocument.text odt; + application/vnd.openxmlformats-officedocument.presentationml.presentation + pptx; + application/vnd.openxmlformats-officedocument.spreadsheetml.sheet + xlsx; + application/vnd.openxmlformats-officedocument.wordprocessingml.document + docx; + application/vnd.wap.wmlc wmlc; + application/x-7z-compressed 7z; + application/x-cocoa cco; + application/x-java-archive-diff jardiff; + application/x-java-jnlp-file jnlp; + application/x-makeself run; + application/x-perl pl pm; + application/x-pilot prc pdb; + application/x-rar-compressed rar; + application/x-redhat-package-manager rpm; + application/x-sea sea; + application/x-shockwave-flash swf; + application/x-stuffit sit; + application/x-tcl tcl tk; + application/x-x509-ca-cert der pem crt; + application/x-xpinstall xpi; + application/xhtml+xml xhtml; + application/xspf+xml xspf; + application/zip zip; + + application/octet-stream bin exe dll; + application/octet-stream deb; + application/octet-stream dmg; + application/octet-stream iso img; + application/octet-stream msi msp msm; + + audio/midi mid midi kar; + audio/mpeg mp3; + audio/ogg ogg; + audio/x-m4a m4a; + audio/x-realaudio ra; + + video/3gpp 3gpp 3gp; + video/mp2t ts; + video/mp4 mp4; + video/mpeg mpeg mpg; + video/quicktime mov; + video/webm webm; + video/x-flv flv; + video/x-m4v m4v; + video/x-mng mng; + video/x-ms-asf asx asf; + video/x-ms-wmv wmv; + video/x-msvideo avi; +} diff --git a/nginx/mime.types.default b/nginx/mime.types.default new file mode 100644 index 000000000..296125695 --- /dev/null +++ b/nginx/mime.types.default @@ -0,0 +1,97 @@ + +types { + text/html html htm shtml; + text/css css; + text/xml xml; + image/gif gif; + image/jpeg jpeg jpg; + application/javascript js; + application/atom+xml atom; + application/rss+xml rss; + + text/mathml mml; + text/plain txt; + text/vnd.sun.j2me.app-descriptor jad; + text/vnd.wap.wml wml; + text/x-component htc; + + image/png png; + image/svg+xml svg svgz; + image/tiff tif tiff; + image/vnd.wap.wbmp wbmp; + image/webp webp; + image/x-icon ico; + image/x-jng jng; + image/x-ms-bmp bmp; + + font/woff woff; + font/woff2 woff2; + + application/java-archive jar war ear; + application/json json; + application/mac-binhex40 hqx; + application/msword doc; + application/pdf pdf; + application/postscript ps eps ai; + application/rtf rtf; + application/vnd.apple.mpegurl m3u8; + application/vnd.google-earth.kml+xml kml; + application/vnd.google-earth.kmz kmz; + application/vnd.ms-excel xls; + application/vnd.ms-fontobject eot; + application/vnd.ms-powerpoint ppt; + application/vnd.oasis.opendocument.graphics odg; + application/vnd.oasis.opendocument.presentation odp; + application/vnd.oasis.opendocument.spreadsheet ods; + application/vnd.oasis.opendocument.text odt; + application/vnd.openxmlformats-officedocument.presentationml.presentation + pptx; + application/vnd.openxmlformats-officedocument.spreadsheetml.sheet + xlsx; + application/vnd.openxmlformats-officedocument.wordprocessingml.document + docx; + application/vnd.wap.wmlc wmlc; + application/x-7z-compressed 7z; + application/x-cocoa cco; + application/x-java-archive-diff jardiff; + application/x-java-jnlp-file jnlp; + application/x-makeself run; + application/x-perl pl pm; + application/x-pilot prc pdb; + application/x-rar-compressed rar; + application/x-redhat-package-manager rpm; + application/x-sea sea; + application/x-shockwave-flash swf; + application/x-stuffit sit; + application/x-tcl tcl tk; + application/x-x509-ca-cert der pem crt; + application/x-xpinstall xpi; + application/xhtml+xml xhtml; + application/xspf+xml xspf; + application/zip zip; + + application/octet-stream bin exe dll; + application/octet-stream deb; + application/octet-stream dmg; + application/octet-stream iso img; + application/octet-stream msi msp msm; + + audio/midi mid midi kar; + audio/mpeg mp3; + audio/ogg ogg; + audio/x-m4a m4a; + audio/x-realaudio ra; + + video/3gpp 3gpp 3gp; + video/mp2t ts; + video/mp4 mp4; + video/mpeg mpeg mpg; + video/quicktime mov; + video/webm webm; + video/x-flv flv; + video/x-m4v m4v; + video/x-mng mng; + video/x-ms-asf asx asf; + video/x-ms-wmv wmv; + video/x-msvideo avi; +} diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 000000000..b1e73f315 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,122 @@ +# For more information on configuration, see: +# * Official English Documentation: http://nginx.org/en/docs/ +# * Official Russian Documentation: http://nginx.org/ru/docs/ + +user nginx; +worker_processes auto; +error_log /var/log/nginx/error.log; +pid /var/run/nginx.pid; + +# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. +include /usr/share/nginx/modules/*.conf; + +events { + worker_connections 1024; +} + +http { + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + # Load modular configuration files from the /etc/nginx/conf.d directory. + # See http://nginx.org/en/docs/ngx_core_module.html#include + # for more information. + include /etc/nginx/conf.d/*.conf; + + index index.html index.htm; + + server { + listen 80 ; + listen [::]:80 ; + server_name localhost; + root /usr/share/nginx/html; + + # Load configuration files for the default server block. + include /etc/nginx/default.d/*.conf; + + location / { + } + + # redirect server error pages to the static page /40x.html + # + error_page 404 /404.html; + location = /40x.html { + } + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + } + + # proxy the PHP scripts to Apache listening on 127.0.0.1:80 + # + #location ~ \.php$ { + # proxy_pass http://127.0.0.1; + #} + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + #location ~ \.php$ { + # root html; + # fastcgi_pass 127.0.0.1:9000; + # fastcgi_index index.php; + # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; + # include fastcgi_params; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} + } + +# Settings for a TLS enabled server. +# +# server { +# listen 443 ssl http2 ; +# listen [::]:443 ssl http2 ; +# server_name _; +# root /usr/share/nginx/html; +# +# ssl_certificate "/etc/pki/nginx/server.crt"; +# ssl_certificate_key "/etc/pki/nginx/private/server.key"; +# # It is *strongly* recommended to generate unique DH parameters +# # Generate them with: openssl dhparam -out /etc/pki/nginx/dhparams.pem 2048 +# #ssl_dhparam "/etc/pki/nginx/dhparams.pem"; +# ssl_session_cache shared:SSL:1m; +# ssl_session_timeout 10m; +# ssl_protocols TLSv1 TLSv1.1 TLSv1.2; +# ssl_ciphers HIGH:SEED:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!RSAPSK:!aDH:!aECDH:!EDH-DSS-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA:!SRP; +# ssl_prefer_server_ciphers on; +# +# # Load configuration files for the default server block. +# include /etc/nginx/default.d/*.conf; +# +# location / { +# } +# +# error_page 404 /404.html; +# location = /40x.html { +# } +# +# error_page 500 502 503 504 /50x.html; +# location = /50x.html { +# } +# } + +} diff --git a/nginx/nginx.conf.default b/nginx/nginx.conf.default new file mode 100644 index 000000000..f9ebe57e7 --- /dev/null +++ b/nginx/nginx.conf.default @@ -0,0 +1,117 @@ + +#user nobody; +worker_processes 1; + +#error_log logs/error.log; +#error_log logs/error.log notice; +#error_log logs/error.log info; + +#pid logs/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include mime.types; + default_type application/octet-stream; + + #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + # '$status $body_bytes_sent "$http_referer" ' + # '"$http_user_agent" "$http_x_forwarded_for"'; + + #access_log logs/access.log main; + + sendfile on; + #tcp_nopush on; + + #keepalive_timeout 0; + keepalive_timeout 65; + + #gzip on; + + server { + listen 8080; + server_name localhost; + + #charset koi8-r; + + #access_log logs/host.access.log main; + + location / { + root html; + index index.html index.htm; + } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root html; + } + + # proxy the PHP scripts to Apache listening on 127.0.0.1:80 + # + #location ~ \.php$ { + # proxy_pass http://127.0.0.1; + #} + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + #location ~ \.php$ { + # root html; + # fastcgi_pass 127.0.0.1:9000; + # fastcgi_index index.php; + # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; + # include fastcgi_params; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} + } + + + # another virtual host using mix of IP-, name-, and port-based configuration + # + #server { + # listen 8000; + # listen somename:8080; + # server_name somename alias another.alias; + + # location / { + # root html; + # index index.html index.htm; + # } + #} + + + # HTTPS server + # + #server { + # listen 443 ssl; + # server_name localhost; + + # ssl_certificate cert.pem; + # ssl_certificate_key cert.key; + + # ssl_session_cache shared:SSL:1m; + # ssl_session_timeout 5m; + + # ssl_ciphers HIGH:!aNULL:!MD5; + # ssl_prefer_server_ciphers on; + + # location / { + # root html; + # index index.html index.htm; + # } + #} + include servers/*; +} diff --git a/nginx/scgi_params b/nginx/scgi_params new file mode 100644 index 000000000..6d4ce4f3e --- /dev/null +++ b/nginx/scgi_params @@ -0,0 +1,17 @@ + +scgi_param REQUEST_METHOD $request_method; +scgi_param REQUEST_URI $request_uri; +scgi_param QUERY_STRING $query_string; +scgi_param CONTENT_TYPE $content_type; + +scgi_param DOCUMENT_URI $document_uri; +scgi_param DOCUMENT_ROOT $document_root; +scgi_param SCGI 1; +scgi_param SERVER_PROTOCOL $server_protocol; +scgi_param REQUEST_SCHEME $scheme; +scgi_param HTTPS $https if_not_empty; + +scgi_param REMOTE_ADDR $remote_addr; +scgi_param REMOTE_PORT $remote_port; +scgi_param SERVER_PORT $server_port; +scgi_param SERVER_NAME $server_name; diff --git a/nginx/scgi_params.default b/nginx/scgi_params.default new file mode 100644 index 000000000..6d4ce4f3e --- /dev/null +++ b/nginx/scgi_params.default @@ -0,0 +1,17 @@ + +scgi_param REQUEST_METHOD $request_method; +scgi_param REQUEST_URI $request_uri; +scgi_param QUERY_STRING $query_string; +scgi_param CONTENT_TYPE $content_type; + +scgi_param DOCUMENT_URI $document_uri; +scgi_param DOCUMENT_ROOT $document_root; +scgi_param SCGI 1; +scgi_param SERVER_PROTOCOL $server_protocol; +scgi_param REQUEST_SCHEME $scheme; +scgi_param HTTPS $https if_not_empty; + +scgi_param REMOTE_ADDR $remote_addr; +scgi_param REMOTE_PORT $remote_port; +scgi_param SERVER_PORT $server_port; +scgi_param SERVER_NAME $server_name; diff --git a/nginx/uwsgi_params b/nginx/uwsgi_params new file mode 100644 index 000000000..09c732cd6 --- /dev/null +++ b/nginx/uwsgi_params @@ -0,0 +1,17 @@ + +uwsgi_param QUERY_STRING $query_string; +uwsgi_param REQUEST_METHOD $request_method; +uwsgi_param CONTENT_TYPE $content_type; +uwsgi_param CONTENT_LENGTH $content_length; + +uwsgi_param REQUEST_URI $request_uri; +uwsgi_param PATH_INFO $document_uri; +uwsgi_param DOCUMENT_ROOT $document_root; +uwsgi_param SERVER_PROTOCOL $server_protocol; +uwsgi_param REQUEST_SCHEME $scheme; +uwsgi_param HTTPS $https if_not_empty; + +uwsgi_param REMOTE_ADDR $remote_addr; +uwsgi_param REMOTE_PORT $remote_port; +uwsgi_param SERVER_PORT $server_port; +uwsgi_param SERVER_NAME $server_name; diff --git a/nginx/uwsgi_params.default b/nginx/uwsgi_params.default new file mode 100644 index 000000000..09c732cd6 --- /dev/null +++ b/nginx/uwsgi_params.default @@ -0,0 +1,17 @@ + +uwsgi_param QUERY_STRING $query_string; +uwsgi_param REQUEST_METHOD $request_method; +uwsgi_param CONTENT_TYPE $content_type; +uwsgi_param CONTENT_LENGTH $content_length; + +uwsgi_param REQUEST_URI $request_uri; +uwsgi_param PATH_INFO $document_uri; +uwsgi_param DOCUMENT_ROOT $document_root; +uwsgi_param SERVER_PROTOCOL $server_protocol; +uwsgi_param REQUEST_SCHEME $scheme; +uwsgi_param HTTPS $https if_not_empty; + +uwsgi_param REMOTE_ADDR $remote_addr; +uwsgi_param REMOTE_PORT $remote_port; +uwsgi_param SERVER_PORT $server_port; +uwsgi_param SERVER_NAME $server_name; diff --git a/nginx/win-utf b/nginx/win-utf new file mode 100644 index 000000000..ed8bc007a --- /dev/null +++ b/nginx/win-utf @@ -0,0 +1,126 @@ + +# This map is not a full windows-1251 <> utf8 map: it does not +# contain Serbian and Macedonian letters. If you need a full map, +# use contrib/unicode2nginx/win-utf map instead. + +charset_map windows-1251 utf-8 { + + 82 E2809A ; # single low-9 quotation mark + + 84 E2809E ; # double low-9 quotation mark + 85 E280A6 ; # ellipsis + 86 E280A0 ; # dagger + 87 E280A1 ; # double dagger + 88 E282AC ; # euro + 89 E280B0 ; # per mille + + 91 E28098 ; # left single quotation mark + 92 E28099 ; # right single quotation mark + 93 E2809C ; # left double quotation mark + 94 E2809D ; # right double quotation mark + 95 E280A2 ; # bullet + 96 E28093 ; # en dash + 97 E28094 ; # em dash + + 99 E284A2 ; # trade mark sign + + A0 C2A0 ; #   + A1 D18E ; # capital Byelorussian short U + A2 D19E ; # small Byelorussian short u + + A4 C2A4 ; # currency sign + A5 D290 ; # capital Ukrainian soft G + A6 C2A6 ; # borken bar + A7 C2A7 ; # section sign + A8 D081 ; # capital YO + A9 C2A9 ; # (C) + AA D084 ; # capital Ukrainian YE + AB C2AB ; # left-pointing double angle quotation mark + AC C2AC ; # not sign + AD C2AD ; # soft hypen + AE C2AE ; # (R) + AF D087 ; # capital Ukrainian YI + + B0 C2B0 ; # ° + B1 C2B1 ; # plus-minus sign + B2 D086 ; # capital Ukrainian I + B3 D196 ; # small Ukrainian i + B4 D291 ; # small Ukrainian soft g + B5 C2B5 ; # micro sign + B6 C2B6 ; # pilcrow sign + B7 C2B7 ; # · + B8 D191 ; # small yo + B9 E28496 ; # numero sign + BA D194 ; # small Ukrainian ye + BB C2BB ; # right-pointing double angle quotation mark + + BF D197 ; # small Ukrainian yi + + C0 D090 ; # capital A + C1 D091 ; # capital B + C2 D092 ; # capital V + C3 D093 ; # capital G + C4 D094 ; # capital D + C5 D095 ; # capital YE + C6 D096 ; # capital ZH + C7 D097 ; # capital Z + C8 D098 ; # capital I + C9 D099 ; # capital J + CA D09A ; # capital K + CB D09B ; # capital L + CC D09C ; # capital M + CD D09D ; # capital N + CE D09E ; # capital O + CF D09F ; # capital P + + D0 D0A0 ; # capital R + D1 D0A1 ; # capital S + D2 D0A2 ; # capital T + D3 D0A3 ; # capital U + D4 D0A4 ; # capital F + D5 D0A5 ; # capital KH + D6 D0A6 ; # capital TS + D7 D0A7 ; # capital CH + D8 D0A8 ; # capital SH + D9 D0A9 ; # capital SHCH + DA D0AA ; # capital hard sign + DB D0AB ; # capital Y + DC D0AC ; # capital soft sign + DD D0AD ; # capital E + DE D0AE ; # capital YU + DF D0AF ; # capital YA + + E0 D0B0 ; # small a + E1 D0B1 ; # small b + E2 D0B2 ; # small v + E3 D0B3 ; # small g + E4 D0B4 ; # small d + E5 D0B5 ; # small ye + E6 D0B6 ; # small zh + E7 D0B7 ; # small z + E8 D0B8 ; # small i + E9 D0B9 ; # small j + EA D0BA ; # small k + EB D0BB ; # small l + EC D0BC ; # small m + ED D0BD ; # small n + EE D0BE ; # small o + EF D0BF ; # small p + + F0 D180 ; # small r + F1 D181 ; # small s + F2 D182 ; # small t + F3 D183 ; # small u + F4 D184 ; # small f + F5 D185 ; # small kh + F6 D186 ; # small ts + F7 D187 ; # small ch + F8 D188 ; # small sh + F9 D189 ; # small shch + FA D18A ; # small hard sign + FB D18B ; # small y + FC D18C ; # small soft sign + FD D18D ; # small e + FE D18E ; # small yu + FF D18F ; # small ya +} From d9446d88d3cdeecb187ea0298e1c41357e6dc943 Mon Sep 17 00:00:00 2001 From: zxc8207 Date: Thu, 18 Jun 2020 07:01:42 +0800 Subject: [PATCH 11/14] return behavior of bin files --- bin/run_dev_server.bash | 2 +- bin/run_shell.bash | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/run_dev_server.bash b/bin/run_dev_server.bash index 5842921ce..9761d15aa 100755 --- a/bin/run_dev_server.bash +++ b/bin/run_dev_server.bash @@ -1,3 +1,3 @@ #!/usr/bin/env bash -docker-compose up app nginx +docker-compose up app diff --git a/bin/run_shell.bash b/bin/run_shell.bash index 45d565952..5ee8a505c 100755 --- a/bin/run_shell.bash +++ b/bin/run_shell.bash @@ -1,3 +1,3 @@ #!/usr/bin/env bash -docker-compose run --rm --service-ports --entrypoint /bin/bash nginx +docker-compose run --rm --service-ports --entrypoint /bin/bash app From 4a3fb5c457520c4a212112962a60101a75030f8d Mon Sep 17 00:00:00 2001 From: zxc8207 Date: Thu, 18 Jun 2020 15:05:22 +0800 Subject: [PATCH 12/14] this file was in the folder but does not compile --- webapp.conf | 1 + 1 file changed, 1 insertion(+) create mode 120000 webapp.conf diff --git a/webapp.conf b/webapp.conf new file mode 120000 index 000000000..5a783542b --- /dev/null +++ b/webapp.conf @@ -0,0 +1 @@ +/opt/elasticbeanstalk/support/conf/webapp.conf \ No newline at end of file From 8c25947745eaabb827fd5a9888450176bb20f609 Mon Sep 17 00:00:00 2001 From: zxc8207 Date: Tue, 30 Jun 2020 14:42:57 +0800 Subject: [PATCH 13/14] basic documentation to configuration line --- nginx/conf.d/1_rate_limit.conf | 2 ++ nginx/conf.d/blockips.conf | 7 +++++++ nginx/conf.d/rate_limit.conf | 1 - nginx/conf.d/{1_webapp.conf => webapp.conf} | 6 +++++- 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 nginx/conf.d/1_rate_limit.conf delete mode 100644 nginx/conf.d/rate_limit.conf rename nginx/conf.d/{1_webapp.conf => webapp.conf} (88%) diff --git a/nginx/conf.d/1_rate_limit.conf b/nginx/conf.d/1_rate_limit.conf new file mode 100644 index 000000000..2e30ebbda --- /dev/null +++ b/nginx/conf.d/1_rate_limit.conf @@ -0,0 +1,2 @@ +# Allow 10 Megabyte for zone=one, maximum request rate is 10 per second +limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s; diff --git a/nginx/conf.d/blockips.conf b/nginx/conf.d/blockips.conf index 60b7a16a6..4a00911fd 100644 --- a/nginx/conf.d/blockips.conf +++ b/nginx/conf.d/blockips.conf @@ -1 +1,8 @@ +#block request from IP #deny 192.168.176.1; + +#block request from all +#deny all; + +#allow request from IP (whitelist) +#allow 192.168.176.2; diff --git a/nginx/conf.d/rate_limit.conf b/nginx/conf.d/rate_limit.conf deleted file mode 100644 index 8b1378917..000000000 --- a/nginx/conf.d/rate_limit.conf +++ /dev/null @@ -1 +0,0 @@ - diff --git a/nginx/conf.d/1_webapp.conf b/nginx/conf.d/webapp.conf similarity index 88% rename from nginx/conf.d/1_webapp.conf rename to nginx/conf.d/webapp.conf index 8d81e6e19..4d8a72e51 100644 --- a/nginx/conf.d/1_webapp.conf +++ b/nginx/conf.d/webapp.conf @@ -1,16 +1,17 @@ #Modified from: https://itnext.io/docker-rails-puma-nginx-postgres-999cd8866b18 +#set upstream rail app upstream safecastapi { server app:3000; } -limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s; server{ server_name safecastapi; # define the public application root root /var/www/safecastapi/public; index index.html; + listen 80; # deny requests for files that should never be accessed location ~ /\. { deny all; @@ -34,9 +35,12 @@ server{ } location / { + # place rate limit before request to all location limit_req zone=one; + #serve files to location @rails try_files $uri @rails; } + #define @rails location @rails { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; From 4efc9ca83ce17b5ab5c2cc81b1a52503f4161823 Mon Sep 17 00:00:00 2001 From: zxc8207 Date: Tue, 30 Jun 2020 14:47:44 +0800 Subject: [PATCH 14/14] additional comment --- nginx/conf.d/webapp.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nginx/conf.d/webapp.conf b/nginx/conf.d/webapp.conf index 4d8a72e51..b17b23efb 100644 --- a/nginx/conf.d/webapp.conf +++ b/nginx/conf.d/webapp.conf @@ -35,7 +35,7 @@ server{ } location / { - # place rate limit before request to all location + # place rate limit rule zone=one before request to all location limit_req zone=one; #serve files to location @rails try_files $uri @rails;