Is my NGINX conf file correct - nginx

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.

Related

nginx is not writing logs in access log file

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;

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

EmberJS & Nginx - Routes return 404's

It seems like a simple problem but I cannot find any official information about how to fix it.
The problem: Deploying an EmberJS app to Nginx - all routes return 404's.
The root route / works just fine. However any route besides / fails & returns 404's. Here's how I have my nginx.conf setup:
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;
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /home/ivo/myapp;
index index.html;
location / {
include /etc/nginx/mime.types;
try_files $uri $uri/ /index.html?/$request_uri;
}
}
}
This config is largely based on the nginx.conf that comes with the Nginx Docker image, which I am using.
From what I understand about Nginx, the location / block should be handling my routes, but for some reason it is not.
As a side note, I am shocked that EmberJS does not have any documentation about this at all. I even tried their Nginx config from their deployment section and it too did not work - https://ember-cli.com/user-guide/#deployments
Found & "fixed" the problem. The underlying issue is that the information provided on the Nginx DockerHub page is misleading. It says:
"If you wish to adapt the default configuration, use something like the following to copy it from a running nginx container"
And it provides this line as an example:
"COPY nginx.conf /etc/nginx/nginx.conf"
However, the file located at /etc/nginx/nginx.conf was not the file I needed. Instead, the file I needed to change/replace was located here : "/etc/nginx/conf.d/default.conf"
The code I pasted above in the Question portion worked fine; it was the location that was wrong.

First time running a ubuntu server is it possible I have nginx installed in two places?

I have two paths:
/etc/nginx/sites-enabled
/opt/nginx/conf/nginx.conf
Both contain an .conf file, is it possible I have nginx installed in two locations? When I edit the first /etc/ conf file, I can control what is served, it appears the /opt conf file is ignored. Why?
conf 1:
server {
listen 80;
server_name www.mydomain.com;
access_log /var/www/mydomain/logs/access.log;
root /var/www/mydomain/;
index me.html me.js;
}
~
conf 2 (ignored at /opt/nginx/conf/nginx.conf
events {
worker_connections 1024;
}
http {
passenger_root /usr/local/rvm/gems/ruby-1.9.3-p0/gems/passenger-3.0.11;
passenger_ruby /usr/local/rvm/wrappers/ruby-1.9.3-p0/ruby;
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;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name www.mydomain.com;
root /var/www/hello/releases/current/public/;
passenger_enabled on;
}
server {
listen 80;
server_name localhost;
No, you only have one installation.
/opt/local/nginx/conf is where the base configuration for the nginx server is.
/etc/nginx/sites-enabled is where you'd symlink site you want to be active (from /etc/nginx/sites-available.
/etc/nginx/sites-available should contain the individual conf files for virtual hosts.
There should be one file in the sites-available folder (if you haven't added any more). That will be the one being used. It may not be named ending .conf

Resources