Skip to content

Commit

Permalink
fix(nginx): a hotfix to disable setting Host header on /media routes
Browse files Browse the repository at this point in the history
  • Loading branch information
ananyo141 committed Apr 12, 2024
1 parent 9756459 commit ce4c644
Showing 1 changed file with 135 additions and 40 deletions.
175 changes: 135 additions & 40 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
## NOTE: https://github.com/minio/minio/blob/master/docs/orchestration/docker-compose/nginx.conf

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
Expand All @@ -20,6 +18,10 @@

# Default server configuration
#

limit_req_zone $binary_remote_addr zone=mylimit:10m rate=10r/s;
client_max_body_size 0;

server {
listen 80 default_server;
listen [::]:80 default_server;
Expand Down Expand Up @@ -47,10 +49,40 @@ server {

server_name _;


# Rate limit
limit_req zone=mylimit burst=20 nodelay;
limit_req_status 429;
limit_conn_status 429;
# To allow special characters in headers
ignore_invalid_headers off;
# Allow any size file to be uploaded.
# To disable buffering
proxy_buffering off;
proxy_request_buffering off;

proxy_set_header Host $http_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_connect_timeout 300;
# Default is HTTP/1, keepalive is only enabled in HTTP/1.1
proxy_http_version 1.1;
proxy_set_header Connection "";
chunked_transfer_encoding off;

# To support websocket
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# try_files $uri $uri/ =404;

proxy_pass http://localhost:8001;
#proxy_pass http://34.93.62.62;
}

# pass PHP scripts to FastCGI server
Expand Down Expand Up @@ -92,10 +124,8 @@ server {
# }
#}

# Rate limit
limit_req_zone $binary_remote_addr zone=mylimit:10m rate=10r/s;
# Set to a value such as 1000m; to restrict file size to a specific value
client_max_body_size 0;


server {

# SSL configuration
Expand All @@ -118,9 +148,10 @@ server {

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name videosite.ddns.net; # managed by Certbot
server_name videosite.ddns.net; # managed by Certbot

# Rate limit

# Rate limit
limit_req zone=mylimit burst=20 nodelay;
limit_req_status 429;
limit_conn_status 429;
Expand All @@ -141,44 +172,107 @@ server {
proxy_http_version 1.1;
proxy_set_header Connection "";
chunked_transfer_encoding off;

# To support websocket
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

location /media {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, OPTIONS';
#
# Custom headers and headers various browsers *should* be OK with but aren't
#
# add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Allow-Headers' '*';
#
# Tell client that this pre-flight info is valid for 20 days
#
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
#add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
add_header 'Access-Control-Allow-Headers' '*';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
#add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
add_header 'Access-Control-Allow-Headers' '*';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
}
#proxy_set_header 'Host' 'video-bucket:9000';
proxy_pass http://localhost:8001;
#proxy_pass http://34.93.62.62;
}
location / {
# https://enable-cors.org/server_nginx.html
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
#
# Custom headers and headers various browsers *should* be OK with but aren't
#
# add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Allow-Headers' '*';
#
# Tell client that this pre-flight info is valid for 20 days
#
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
}
proxy_pass http://localhost:8001;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, OPTIONS';
#
# Custom headers and headers various browsers *should* be OK with but aren't
#
# add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Allow-Headers' '*';
#
# Tell client that this pre-flight info is valid for 20 days
#
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
#add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
add_header 'Access-Control-Allow-Headers' '*';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
#add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
add_header 'Access-Control-Allow-Headers' '*';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
}
proxy_set_header 'Host' 'video-bucket:9000';
proxy_pass http://localhost:8001;
#proxy_pass http://34.93.62.62;
}

# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
# fastcgi_pass unix:/run/php/php7.4-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}


listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/videosite.ddns.net/fullchain.pem; # managed by Certbot
Expand All @@ -187,6 +281,7 @@ server {
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
if ($host = videosite.ddns.net) {
return 301 https://$host$request_uri;
Expand Down

0 comments on commit ce4c644

Please sign in to comment.