Nginx 404 not found with no suffix / - docker

I'm trying to run Nginx on my local.
with the next default.conf:
server {
listen 80;
listen [::]:80;
server_name localhost;
root /usr/share/nginx/html;
#access_log /var/log/nginx/host.access.log main;
# 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;
}
location /buy/ {
alias /var/www/buy/;
}
location /sell/ {
alias /var/www/sell/;
}
}
When I run Nginx and try to hit localhost:80/buy/ I get the expected page.
but when I hit localhost:80/buy (without the suffix /) I got 404 not found.
any idea?

Related

I tried to use nginx as a reverse proxy within a docker container, but it didn't work

I build a nginx image with this content in the Dockerfile:
FROM nginx
COPY nginx.conf /etc/nginx
The content of the nginx.conf file is the following:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream server1 {
server localhost:8081;
}
upstream server2 {
server localhost:8082;
}
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location /server1/ {
proxy_pass http://server1;
}
location /server2/ {
proxy_pass http://server2;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
I have two node servers running on port 8081 and 8082 which working properly when visited directly. However when I visit http:localhost:8080/server1/ or http:localhost:8080/server2/ the response says can't GET server1/server2 respectively.
I find out that in the /etc/nginx/modules folder within the container there is no "upstream" related module listed there. Could it be that the "upstream" function not supported because of the absence of the related "upstream" module?
Can someone tell me how to fix the problem? Thank a lot.

nginx configuration for ssl certificate installation with rails application

I have a site that I built using ruby on rails on nginx server with passenger. My client decided to install ssl certificate.I am a newbie to that kind of issues and I have never did it before and I need to confirm that my sites-enabled/default file is configured properly.
My current configuration is :
server {
listen 80;
listen [::]:80 ipv6only=on;
server_name www.mysite.com;
passenger_enabled on;
rails_env production;
root /home/directory;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
and for adding ssl certificate, I will add another server block like below:
server {
listen 443;
server_name www.mysite.com;
passenger_enabled on;
rails_env production;
root /home/directory;
ssl on;
ssl_certificate /etc/ssl/my_certificate;
ssl_certificate_key /etc/ssl/my_private_key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
ssl_prefer_server_ciphers on;
ssl_session_timeout 10m;
ssl_session_cache shared:SSL:10m;
ssl_stapling on
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
is that a right way and parameters to configure nginx or I need to combine them in one server block ?
is there any thing missing should I add to the previous config ?
in the :server_name www.mysite.com;
can I replace it with my IP address instead of the domain name ?
Thanks for your time in advance
You can have HTTP and HTTPS servers in the same server section
server {
listen 80;
listen [::]:80 ipv6only=on;
listen 443 ssl;
...
}
For complete SSL related configuration I would recommend to use Mozilla generator
Yes, but you shouldn't. Nginx will match your first server section even if you haven't set server_name properly, but such configuration is hard to support and troubleshoot

How to install and configure a server with nginx + rails API under Windows?

There are two questions:
How to deploy a part of the RAILS API application on the nginx server (via Windows), at the moment I have deployed only the client part written in Angular, now I need to display the data from the server side written in Rails.
my nginx.conf file is bellow
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html/dist;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html/dist;
}
}
}
After updating the page, if the link is specified in about this format http://localhost/login, it will return an error 404 although it worked before updating. How can this be remedied?

Ruby Passenger Root:Root User

I have the following problem with passenger
Permission denied # rb_sysopen
I have only root user in server and install all with root user.
Config Passenger
server {
listen 80;
server_name localhost;
passenger_enabled on;
passenger_app_env testing;
passenger_user root;
passenger_group root;
root /opt/my_app/public;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
Passenger Version 5.1.8
Thanks for your time!!
xD

Ruby on rails nginx gives directory of is forbidden

I have an nginx server with passenger that I am trying to run a ruby on rails app. I am using rbenv and am deploying using capistrano.
I keep getting an error message that is as follows:
directory index of "[/srv/[directory]]" is forbidden, client: [my client ip], server: [my domain], request: "GET / HTTP/1.1", host: "[my domain]"
My nginx config for the site:
server {
listen 80;
server_name [my domain];
passenger_enabled on;
rails_env production;
root /srv/[my app name]/current/public;
passenger_ruby /home/deploy/.rbenv/shims/ruby;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
passenger_enabled on;
}
location / {
passenger_enabled on;
}
}
And my config for passenger in my nginx.conf file is as follows:
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /home/deploy/.rbenv/shims/ruby;

Resources