gzip compression showing off even though enabled - nginx

I'm unsure as to why gzip it showing as failed on both webpagetest and gtmetrix when in my nginx config I have it enabled.
I'm currently running nginx version: nginx/1.10.1
Here is my current nginx config
# HTTPS
server {
listen 443 ssl http2 default_server;
root /home/www/youtstream;
server_name dev.yout.com
gzip_disable "msie6";
access_log off;
error_log off;
gzip_vary on;
gzip on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;
ssl on;
ssl_certificate /srv/dehydrated/certs/dev.yout.com/fullchain.pem;
ssl_certificate_key /srv/dehydrated/certs/dev.yout.com/privkey.pem;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /static {
alias /home/www/youtstream/static/;
}
location ~* \.(jpg|jpeg|png|gif|ico|css|js|mp4|woff2)$ {
expires max;
}
Here is the results of webpagetest and gtmetrix

Related

Nginx location regex configuration issue - Not capturing subdomains of location specified

I am using below nginx file. I have hosted multiple frontend (angular) projects on single server. So, I want to access different project on different path.
When I hit url www.*********.com/st_admit/dashboard
I want to access project place in directory /usr/share/nginx/html2; but nginx is redirecting to root domain i.e. "/" and open the project placed in /usr/share/nginx/html;
Please check below configuration file and let me know how I can fix the nginx location regex.
client_max_body_size 10M;
upstream django {
ip_hash;
server django_gunicorn:8001;
}
server {
server_name *************.*** www.******.***;
listen 443 ssl;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
ssl_certificate /etc/nginx/***********.crt;
ssl_certificate_key /etc/nginx/*************.key;
client_max_body_size 4G;
proxy_read_timeout 20000;
proxy_connect_timeout 20000;
proxy_send_timeout 20000;
keepalive_timeout 200;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
server_tokens off;
ssl_protocols TLSv1.2 TLSv1.3;
root /usr/share/nginx/html;
location ^~ /st_admin/(.*) {
alias /usr/share/nginx/html2;
index index.html index.htm;
include /etc/nginx/mime.types;
gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://django;
break;
}
}
location / {
root /usr/share/nginx/html;
index index.html index.htm;
include /etc/nginx/mime.types;
gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
try_files $uri $uri/ /index.html;
}
}
I tried below location configurations, but none of these are working.
location ^~ /st_admin
location ^~ /st_admin/*
location ^~ /st_admin/(.*)

Caching images, js, css with NGINX

I have a Nginx server with follow parametrs `
server {
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /home/dev/main.crt;
ssl_certificate_key /home/dev/crt.private;
server_name dev;
root /home/dev/ui;
index index.html;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types
application/atom+xml
application/geo+json
application/javascript
application/x-javascript
application/json
application/ld+json
application/manifest+json
application/rdf+xml
application/rss+xml
application/xhtml+xml
application/xml
font/eot
font/otf
font/ttf
image/svg+xml
text/css
text/javascript
text/plain
text/xml;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:4000$request_uri;
}
location /images {
alias /home/dev/img;
expires 20d;
try_files $uri $uri/ =404;
}
}
`
And when I add
`
location ~* .(?:ico|css|js|gif|jpe?g|png|svg|woff)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control "public";
}
`
the server starts returning errors for all images inside /home/dev/img. Have you ever faced such problem? If Have no clue what is going on, because when I remove the code, everything works fine, and images, js files load with out any issue

nginx reverse proxy working only if port 80 available

I hope somebody can help me to solve/understand this issue as I am totally stuck.
I am a ec2 instance running nginx. This ec2 instance is behind a load balancer.
My nginx configuration, is to reverse the traffic to an external service hosted on azure.
But for demonstration purpose lets assume this external service is example.com
all my infra is working, and my nginx configuration files is like this:
# This is the new file
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
server_names_hash_bucket_size 128;
server {
listen 80; ## listen for ipv4; this line is default and implied
root /usr/share/nginx/html;
index index.html;
server_tokens off; # disable the Server nginx header
# enable gzip
gzip on;
gzip_disable "msie6";
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types
text/plain
text/css
text/js
text/xml
text/javascript
application/javascript
application/x-javascript
application/json
application/xml
application/rss+xml
image/svg+xml;
location / {
# try_files $uri /index.html; # redirect all request to index.html
proxy_pass https://example.com;
}
}
server {
listen 443; ## listen for ipv4; this line is default and implied
root /usr/share/nginx/html;
index index.html;
server_tokens off; # disable the Server nginx header
# enable gzip
gzip on;
gzip_disable "msie6";
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types
text/plain
text/css
text/js
text/xml
text/javascript
application/javascript
application/x-javascript
application/json
application/xml
application/rss+xml
image/svg+xml;
location / {
# try_files $uri /index.html; # redirect all request to index.html
proxy_pass https://example.com;
}
}
##
# 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; # 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_disable "msie6";
# 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/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
With this configuration everything works just fine. But if I remove the server on port 80 and keep only the 443 and reload nginx. On the browser I get the error Bad Gateway
Is the server 80 required for nginx? I checked all the documentation and couldn't find anything.
Please can anyone enlighten me on this issue or just point me on the right path? thank you so much for any help you can provide or hint.
And please if my question is not 100% clear, don't hesitate to ask for details

nginx serves 404 without passing to proxy

I' ve got simple setup to deploy angular, springboot, mysql stack. I'am serving this through nginx, with this configuration
server {
listen 8081;
server_name _;
root /usr/share/nginx/html;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 32;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript font/opentype image/svg+xml image/x-icon application/javascript application/x-font-ttf application/x-font-otf application/font-woff application/font-woff2 application/vnd.ms-fontobject application/octet-stream;
error_log stderr info;
access_log /dev/stdout main;
location /api {
proxy_pass http://backend:8080/;
}
location /app {
root /usr/share/nginx/html;
try_files $uri$args $uri$args/ $uri/ /index.html;
#index index.html index.htm;
}
}
app is served well, but when i try to get localhost:8081/api it ends with 404, and in logs i've see that nginx end with 404, without passing to backend. Am i doing something wrong?

Is there any way to serve 2 app on same server_name using nginx?

This is my first sites-enabled file
server {
listen 80;
listen 443 ssl;
server_name www.cobanextwithzone.test;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types
text/plain
text/css
application/json
application/x-javascript
text/xml
application/xml
application/xml+rss
text/javascript
application/javascript
application/vnd.ms-fontobject
application/x-font-ttf
application/font-woff
font/opentype
image/svg+xml
image/x-icon;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
location / {
proxy_set_header Host $http_host;
proxy_pass http://localhost:3000;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
and this is the second
server {
listen 80;
listen 443 ssl;
server_name www.cobanextwithzone.test;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types
text/plain
text/css
application/json
application/x-javascript
text/xml
application/xml
application/xml+rss
text/javascript
application/javascript
application/vnd.ms-fontobject
application/x-font-ttf
application/font-woff
font/opentype
image/svg+xml
image/x-icon;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
location / {
proxy_set_header Host $http_host;
proxy_pass http://localhost:3000;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
those to file are using same server_name, because I wanted to do microfrontends, so the second app will be served on www.cobanextwithzone.test/thesecondapp/
the problem is when sudo service nginx restart or sudo service nginx reload it shows this on sudo nginx -t
nginx: [warn] conflicting server name "www.cobanextwithzone.test" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "www.cobanextwithzone.test" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "www.cobanextwithzone.test" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "www.cobanextwithzone.test" on 0.0.0.0:443, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Anyone know how to serve 2 app on same server_name?
Thanks!

Resources