I'm trying to set up a docker container using Nginx default image and add a simple health route to it as proposed here.
My config is as follows, and I am placing it under /etc/nginx/conf.d/bacon.conf.
# bacon.conf
server {
listen 80;
location /health {
access_log off;
add_header 'Content-Type' 'application/json';
return 200 '{"status":"Healthy"}';
}
}
When I try to access this /health route I end up getting a 404.
I've noticed there is already a default conf file on etc/nginx/conf.d/ called default.conf.
# default.conf
server {
listen 80;
listen [::]:80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
If I remove this default file from my container or if I merge both of them on a single file, my /health route starts working just fine.
I also checked nginx.conf under /etc/nginx which has this line:
#nginx.conf
...
include /etc/nginx/conf.d/*.conf;
...
From what I understand this should make NGinx mix all files ending in .conf into a single configuration file, shouldn't it?
For the sake of simplicity I would like to keep both files, how can I achieve this?
Related
i've an nginx container used as front-end for a web application.
This is my config file:
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
root /usr/share/nginx/html/shaka-player-master/demo;
index index.html index.htm;
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
If i point to localhost:port it returns me correctly /usr/share/nginx/html/shaka-player-master/demo/index.html ... but i have a problem:
This application, a dash library, needs i run a python script that generate files names "deps.js", base.js and others, hosted in:
/usr/share/nginx/html/shaka-player-master/third_party/closure/goog/base.js
/usr/share/nginx/html/shaka-player-master/dist/deps.js
/usr/share/nginx/html/shaka-player-master/shaka-player.uncompiled.js
These files are inside these folders, but browser returns me 404 because of i don't know how to expose these contents from config file.
I tried adding some code like:
location = third_party/closure/goog/base.js {
root /usr/share/nginx/html/shaka-player-master/third_party/closure/goog/base.js;
}
But still 404.
Can anyone help me?
The correct location and root syntax would be:
location = /third_party/closure/goog/base.js {
root /usr/share/nginx/html/shaka-player-master;
}
location = /dist/deps.js {
root /usr/share/nginx/html/shaka-player-master;
}
location = /shaka-player.uncompiled.js {
root /usr/share/nginx/html/shaka-player-master;
}
See location and root manual pages for details.
There will also be configurations that allow this root to be the default and make the demo location the exception.
However, there is another potential problem - why is your application using localhost:9900 as the server name?
I'm trying to redirect all the requests hitting my page to an image. Inside my default.conf I have this:
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
try_files $uri $uri/ /usr/share/nginx/html/10343632.jpeg;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
the jpeg file is the image and it's located in /usr/share/nginx/html and I have removed all the other files from that directory. Every time I hit the page it gives a :
rewrite or internal redirection cycle while internally redirecting to "/usr/share/nginx/html/10343632.jpeg
I've also tried :
try_files $uri /usr/share/nginx/html/10343632.jpeg;
and
try_files $uri /10343632.jpeg;
and got the same error. The point of this is to serve an image no matter what the user requested.
The location section must account for root such that :
location / {
root /usr/share/nginx/html/;
try_files $uri /10343632.jpeg;
}
and it'll work!
When I am accesing page at http://myIP I am seeing files in folder
var/www/html
instead of
var/www/html/src/public
I have set up following setting in /etc/nginx/sites-available/default:
root /var/www/html/src/public;
index index.html index.htm;
and also restarted nginx.
What could be wrong? Thank you in advance.
You need to define your document root in:
/etc/nginx/nginx.conf
Or define it in your virtual host config file in:
/etc/nginx/conf.d/default.conf
Here is an example default.conf file setup:
server {
listen 80;
listen 443 ssl;
ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
server_name adamsawesomewebsite.tk;
root /var/www/vhosts/adamsawesomewebsite.tk/httpdocs;
index index.php index.html;
#charset koi8-r;
#access_log /var/log/nginx/access.log main;
# redirect server error pages to the static page /40x.html
#
#error_page 404 /404.html;
#location = /40x.html {
#}
location / {
try_files $uri $uri/ /index.php?q=$request_uri;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
I have tried many things but I cant seem to make it work.
I am running CentOS6 64-bit. Latest NGINX version installed.
I cannot seem to go to http://domain.com/phpmyadmin aftet switching from Apache.
Please help, thanks.
Here is my Default.conf:
# The default server
#
server {
listen 80 default_server;
server_name _;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /var/www/html;
index login.php index.php;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /var/www/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
EDIT:
FIXED
Moved the PHPMYADMIN folder from /usr/share to my web directory.
And now you broke the package. For prosperity:
location /phpmyadmin {
root /usr/share;
}
I recently installed NGINX and PHP-FPM on a Centos6 server. I'm able to view other php pages on my site, but for some reason my index.php file gets downloaded rather than processed like a normal php page.
Here is the nginx config:
# The default server
#
server {
listen 80 default_server;
server_name example.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /var/www/html/;
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /index.php {
root /var/www/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /var/www/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
Try to remove this block:
location = /index.php {
root /var/www/html;
}