NGINX Logging on AWS with ec2-user is not happening - amazon-web-services

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

Related

nginx: [emerg] invalid number of arguments in "include" directive

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;
...

NGINX gives 502 error from browsers but not from Postman

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

Nginx routing Django Web App links to wrong path

I have a django app where the hompage routes correctly, but when I try to click on any of the links I get a 404 error. I looked at the logs and see:
*1 open() "/usr/share/nginx/html/pricing" failed (2: No such file or directory)
which tells me that nginx is not looking at my project folder but instead what seems to be a default setting. I am using centos, so I had to manually setup sites-available and sites-enabled, which I have used to get the homepage working. As such there is no default conf to disable. I am unsure how to get nginx to route to my path instead of the default. My nginx.conf file looks like this:
user so_dev;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
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;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*; #added by me
}
I followed a bad tutorial which had a typo in it. If you happen to follow same type, inside your nginx sites-available file you should put:
location /
and NOT
location = /
https://www.shellvoide.com/hacks/installing-django-application-with-nginx-mysql-and-gunicorn-on-ubuntu-vps/

GZIP compression / caching with NGINX

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?

nGinx server_name with regex always being caught (ec2)

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