C
C#2y ago
Dreams

Enabling caching in Nginx

Is there something in my setup files that is disabling caching for my API? /etc/nginx/nginx.conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
worker_connections 768;
# multi_accept on;
}

http {
##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

server_names_hash_bucket_size 128;
include nginx-SalonML.conf;
include nginx-SalonML_API.conf;
}
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
worker_connections 768;
# multi_accept on;
}

http {
##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

server_names_hash_bucket_size 128;
include nginx-SalonML.conf;
include nginx-SalonML_API.conf;
}
1 Reply
Dreams
DreamsOP2y ago
/etc/nginx/nginx-SalonML_API.conf:
server {
listen 80;
listen [::]:80;
server_name api.salonmlsarajevo.com;
return 301 https://api.salonmlsarajevo.com$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;

ssl_certificate /etc/letsencrypt/live/salonmlsarajevo.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/salonmlsarajevo.com/privkey.pem;

server_name api.salonmlsarajevo.com;

root /var/www/SalonML_API/;
index index.html;
autoindex off;

location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;

proxy_cache_bypass $http_upgrade;

proxy_set_header Connection $http_connection;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Server $host;
}
}
server {
listen 80;
listen [::]:80;
server_name api.salonmlsarajevo.com;
return 301 https://api.salonmlsarajevo.com$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;

ssl_certificate /etc/letsencrypt/live/salonmlsarajevo.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/salonmlsarajevo.com/privkey.pem;

server_name api.salonmlsarajevo.com;

root /var/www/SalonML_API/;
index index.html;
autoindex off;

location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;

proxy_cache_bypass $http_upgrade;

proxy_set_header Connection $http_connection;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Server $host;
}
}
/etc/nginx/nginx-SalonML.conf:
server {
listen 80;
listen [::]:80;
server_name salonmlsarajevo.com;
return 301 https://salonmlsarajevo.com$request_uri;
}

server {
listen 443 ssl http2;
listen [::]:443 ssl http2;

ssl_certificate /etc/letsencrypt/live/salonmlsarajevo.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/salonmlsarajevo.com/privkey.pem;

server_name salonmlsarajevo.com;

try_files $uri $uri/ /index.html @proxy;

location @proxy {
proxy_pass http://127.0.0.1:83;
}

root /var/www/SalonML/;
index index.html;
autoindex off;
}
server {
listen 80;
listen [::]:80;
server_name salonmlsarajevo.com;
return 301 https://salonmlsarajevo.com$request_uri;
}

server {
listen 443 ssl http2;
listen [::]:443 ssl http2;

ssl_certificate /etc/letsencrypt/live/salonmlsarajevo.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/salonmlsarajevo.com/privkey.pem;

server_name salonmlsarajevo.com;

try_files $uri $uri/ /index.html @proxy;

location @proxy {
proxy_pass http://127.0.0.1:83;
}

root /var/www/SalonML/;
index index.html;
autoindex off;
}
Etag caching works for the static files, and I'd like to do the same for my API request/responses
Want results from more Discord servers?
Add your server