nginx is not writing logs in access log file - nginx

Nginx is not writing logs in access log file but error log is working fine. I have no clue that what happened, before access log was working fine. I remove access log file but still it's not writing log inside. Any idea what happened? any help will be appreciated. my nginx is running on windows 10.
here is my configuration file
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 C:/nginx/log/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
}

your addressing schema is dedicated to linux environments not windows. you have to use the addressing schema associated with windows. use the code below instead.
access_log C://pathtoyourfile/access.log main;

Related

CentOS displays NGINX page instead of flask app?

I try to deploy a Flask App on centOS with NGINX. The Flask app is served on 127.0.0.1:5000 and is also accessible with curl 127.0.0.1:5000.
I tried to keep it simple and removed all NGINX config files in conf.d and just use nginx.conf. This is the whole content of the nginx.conf file:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
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;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
#include /etc/nginx/conf.d/*.conf;
server {
listen 80;
location / {
proxy_pass http://127.0.0.1:5000/;
proxy_set_header X-Real-IP $remote_addr;
}
}
}
However, NGINX still shows its default page and there seems to be nothing in the world or at least in the nginx.conf file to change this. Is there anything in NGINX that still might require reconfiguration or anything on centOS that could lead to the problem?
I solved it. It was indeed open NGINX commands.
After I ran the following commands it worked:
sudo systemctl stop nginx
sudo systemctl enable nginx
sudo systemctl restart nginx
Maybe it helps someone in the future.

Web page on Vagrant is not updating when I edit the file

I have the file on the Vagrant named index.html, and config the nginx a web server vhost like my.loc, the index.html can access in chrome on my Mac, which the vagrant's host.
Now the problem is :
when I edit the index.html file such as
<html>
<head>
<title>title11</title>
</head>
<body>
</body>
</html>
and then I change the title11 to title22, the web page not change on the chrome.
So first I think it's the cache problem, and I config the nginx.conf like this to forbid the cache :
location ~.*\.(js|css|html|png|jpg)$
{
#expires -1;
add_header Cache-Control no-cache;
add_header Cache-Control no-store;
}
it doesn't work. However, I found that if I run the cmd touch /myweb/index.html on the vagrant, the web page changes on Chrome, but it's not what I want.
EDIT:
this is my nginx.conf
user nginx;
worker_processes auto;
error_log /vagrant/nginx-error.log;
pid /var/run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
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 /vagrant/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 /vagrant/nginx-vhosts/*.conf;
}
Now I found if I edit the index.html on linux in the vagrant, and then the page will change on chrome in my Mac OS.So I think the problem is about vagrant.
I finally resolve the problem to change sendfile on to sendfile off in the nginx.conf.
I get the answer from this article : Clear nginx Cache in Vagrant
This is because:
Sendfile is used to ‘copy data between one file descriptor and another‘ and apparently has some real trouble when run in a virtual machine environment, or at least when run through Virtualbox. Turning this config off in nginx causes the static file to be served via a different method and your changes will be reflected immediately and without question

nginx configuration for expiration header

I need to do 2 things, first set the expiration header to 30d and second to enable the page speed module. Non of them work so far, this is my nginx.conf file
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;
#tcp_nopush on;
keepalive_timeout 65;
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control "public";
}
include /etc/nginx/conf.d/*.conf;
}
For turning on pagespeed, you first need to build your nginx from source with pagespeed's module.
Its very easy! You could just follow Google's instruction here and then here
After you complied Nginx from source with pagespeed module enabled, you could just add this to your conf:
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
To set the expiration header, I think it's better to put your code inside a server block, and then inside the main location block. See this blog post but it uses an if clause if you don't mind.
If you are optimizing your website, maybe consider using gzip on too in your conf. It compress the content before sending them to your clients. It saves you a lot of bandwidth and I think it reduce the latency (faster load).
If you are decided to use gzip with pagespeed, make sure to add below line to your conf and read
pagespeed FetchWithGzip on;

Is my NGINX conf file correct

I am new to NGINX and I can't tell if I set my conf file up properly. I am trying to serve an index.html file located in the data/www directory. I did a lot of research and I can't seem to figure it out. I have nginx installed on a ec2 running centOS 6.5. Any pointers on how to get this up and running would be greatly appreciated. I have been trying to wrap my head around this for a while now. Thank you in advance!
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;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name <my elastic ip address>;
location / {
root /data/www/;
index index.html;
}
}
}
Yes,
Your Configuration file is correct.
NOTE:
working:First check your nginx server is running or not, by typing your ip:port(that you given in conf file) in browser.If running it will display nginx current version details.
ACCESS: you can access your file by using command like this.
http://your_ip_addr:port/application name/file_name
*application name:the name given for that app,
for example
location /html {
......
}
then you application name will become html.

Nginx: you should increase server_names_hash_bucket_size: 32 - did this but no effect

When I run
nginx -t
I get error
nginx: [emerg] could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32
Then I go and update nginx.conf file, line server_names_hash_bucket_size to 32.
Then I run
service nginx reload
Then run again nginx -t and I am getting the same error.
Why it does not take effect and how could I fix this?
Setting to 64 does not throw this error anymore. Probably it was showing current value - 32 which was not enough.
In nginx 1.14, there is no default settings in nginx.conf, so add the server_names_hash_bucket_size 64; into http
http {
include 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 logs/access.log main;
server_names_hash_bucket_size 64;
Incase someone uncommented the line but it still doesn't work, increase the value by 32 to make it 92. So you should have
server_names_hash_bucket_size 96;

Resources