I've tried various methods of implementing GZIP on my nginx server, running a python/flask script. I'm trying to compress and cache static content, but nothing has worked so far.
my /etc/nginx/nginx.conf file looks like this:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
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;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
gzip on;
gzip_buffers 16 8k;
gzip_comp_level 4;
gzip_http_version 1.0;
gzip_min_length 1280;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp;
gzip_vary on;
location ~* \.(svg|jpg|jpeg|png|ico|css|js)$ {
expires 365d;
}
}
}
What am I missing?
Related
I am learning how to deploy AWS for the first time. I am following this guide here: https://www.youtube.com/watch?v=HtWgb_vbyvY.
I am using windows machine while the person in the video uses mac.
I am getting the following error when running ngnix commands on the windows terminal: "nginx: [emerg] CreateFile() "C:/nginx-1.23.0/nginx-1.23.0/mime.types" failed (3: The system cannot find the path specified) in C:\Users\Shi Jie\Downloads\nginx-1.23.0\nginx-1.23.0/conf/nginx.conf:12"
i think it is how i write the path on my ngnix.conf which i write as such
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include \Users\Shi Jie\Downloads\nginx-1.23.0\nginx-1.23.0\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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
client_body_buffer_size 100k;
client_header_buffer_size 1k;
client_max_body_size 100k;
large_client_header_buffers 2 1k;
client_body_timeout 10;
client_header_timeout 10;
keepalive_timeout 5 5;
send_timeout 10;
server_tokens off;
#gzip on; on;
include /etc/nginx/conf.d/*.conf;
}
Can anyone point the way to teach me how to write the path properly? Thank you.
You need to escape spaces, { and ". So change your include line to the following:
...
include /Users/Shi\ Jie/Downloads/nginx-1.23.0/nginx-1.23.0/mime.types;
...
Below is my edited nginx.conf
user ec2-user;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 2048;
}
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;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
}
When I changed the user variable from nginx user to ec2-user, the logs are not getting captured in the /var/log/nginx/access.log file even though the file is present it always remains zero size
I've got a Django application running on Azure App Service using NGINX.
My nginx.conf file is as follow:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
fastcgi_max_temp_file_size 0;
fastcgi_buffers 128 2048k;
fastcgi_buffer_size 2048k;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
server {
listen 8000;
location / {
include uwsgi_params;
uwsgi_pass unix:///tmp/uwsgi.sock;
}
location /static {
alias /app/staticfiles;
}
}
}
daemon off;
Everything works fine, except for one particular API where I include in the header some token (typical bearer token) and it's returning a 502 error from Chrome (in the network tab)
However, when I try to call this from Postman, it's returning the data correctly.
What could be possibly wrong here?
Thanks to #Selcuk's suggestion. I've managed to fix the above error by increasing the buffer-size in iwsgi.ini file
# uwsgi.ini file
buffer-size = 32768
I'm facing an issue with AWS Elastic Beanstalk(Php,Symfony) and gzip.
I'm trying to enable Gzip compression but it work only for .svg files with this configuration :
Folder hierarchy
nginx.config
server {
gzip on;
gzip_static on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml;
gzip_min_length 1400;
}
symfony.config
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip on;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml;
gzip_min_length 1400;
if ($host !~* ^www\.) {
return 301 https://www.$host$request_uri;
}
if ($http_x_forwarded_proto != "https") {
return 301 https://$host$request_uri;
}
}
location ~* \.(?:ico|css|js|gif|jpe?g|png|svg)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control "public";
gzip_static on;
gzip on;
gzip_comp_level 4;
gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml;
}
Is there any way to fix it ?
Thanks to Marcin and Julien B it work now.
I changed the nginx directory to .platform/nginx/nginx.conf and get a default nginx config from the beanstalk instance, and set myconfig on it.
nginx.conf
#Elastic Beanstalk Nginx Configuration File
user nginx;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
worker_processes auto;
worker_rlimit_nofile 65235;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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"';
include conf.d/*.conf;
map $http_upgrade $connection_upgrade {
default "upgrade";
}
server {
listen 80 default_server;
access_log /var/log/nginx/access.log main;
client_header_timeout 60;
client_body_timeout 60;
keepalive_timeout 60;
#gzip off;
#gzip_comp_level 4;
#gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip on;
gzip_static on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types application/javascript application/rss+xml application/vnd.ms-fontobject application/x-font application/x-font-opentype application/x-font-otf application/x-font-truetype application/x-font-ttf application/x-javascript application/xhtml+xml application/xml application/json font/opentype font/otf font/ttf image/svg+xml image/x-icon text/css text/html text/javascript text/plain text/xml;
gzip_min_length 1400;
# Include the Elastic Beanstalk generated locations
include conf.d/elasticbeanstalk/*.conf;
}
}
Have a ec2 server that has different subdomains that i wish to point to different services, trying to use the server_name to catch each but not working, always defaults to first conf (admin). In the example below I want example.com to use default.conf and admin.example.com to use admin.conf.
#nginx.conf
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_comp_level 9;
gzip_proxied any;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript applicat$
gzip_min_length 1000;
gzip_disable "MSIE [1-6]\.";
underscores_in_headers on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*.conf;
index index.html index.htm;
}
#/sites-enabled/default.conf
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
}
#/sites-enabled/admin.conf
server {
listen 80;
server_name ^(www\.)?admin(-dev|-sandbox|)$ *.example.com;
#server_name admin.example.com # This is still caught by all routes
access_log /var/log/nginx/admin.access.log;
location / {
root /usr/share/admin-frontend;
index index.html index.html;
}
}
And I have setup the hosts file
127.0.0.1 localhost
127.0.0.1 admin.localhost
127.0.0.1 admin-dev.localhost
127.0.0.1 admin-sandbox.localhost
Currently if i use the public dns for ec2 (http://ec2-XX-XX-XX-XX.compute-1.amazonaws.com/) the admin config is triggered even though the server doesn't match.
Try this regexp:
server_name ~^(www\.)?admin(-dev|-sandbox|)\.example\.com$;
And I cant find *.example.com domain in your hosts file, maybe you need add them also
127.0.0.1 example.com admin.example.com admin-dev.example.com
etc