nginx location 404 not found for reactjs - reactjs

Works only main URL example.com if I type example.com/somepage I observe 404 error in the browser.
My nginx configuration:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html/dist;
index index.html;
server_name _;
location / {
try_files $uri /index.html;
}
}
Actually it is all that I have, I'm pretty new in Ubuntu

Related

Why Nginx load balancer is not serving js/css files from nginx nodes?

I have load balancer with really simple config for domain.com:
server {
listen 80;
server_name domain.com;
location / {
proxy_pass http://dev-admin;
}
}
upstream dev-admin {
server ip1:8001;
server ip2:8001;
server ip3:8001;
}
IMPORTANT:
Ip1, Ip2 and Ip3 are docker containers that are made by making docker swarm service.
Now when you open ip1:8001 or any other ip2 or ip3 you got website and all is good. Website is from react build.
On each node ip1, ip2 and ip3 i have nginx with this config:
server {
listen 80;
listen [::]:80;
root /usr/share/nginx/html;
index index.html index.htm index.nginx-debian.html;
server_name localhost;
location / {
try_files $uri /index.html;
}
}
So when you try website on domain.com instead serving css or js files it is serving index.html response. So domain.com/static/some.js -> this shows in the response index.html content.
I have no idea what else to debug.
Help. Please.
It turned, out I was missing $uri/ on nodes config.
So it is:
location / {
try_files $uri $uri/ /index.html;
}

Setup two React websites on the same domain with NGINX, deployed to separate folders

I am trying to configure NGINX to serve two separate websites on the same domain, with one of the websites being served at the top level of the domain, and the other accessible from domain.com/gol
The first websites files are on the server located at /var/www/morderindustries.com/public
The second websites files are on the server located at /var/www/morderindustries.com/gol
This is my nginx config for the website:
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
ssl on;
ssl_certificate /etc/ssl/ssl-bundle.crt;
ssl_certificate_key /etc/nginx/ssl-certs/www.morrder.com.key;
server_name morrder.com www.morrder.com;
# index index.html
error_log /var/log/nginx/morderindustries.com.error.log;
access_log /var/log/nginx/morderindustries.com.access.log;
location / {
root /var/www/morderindustries.com/public;
try_files $uri $uri/ /index.html =404;
}
location /gol {
root /var/www/morderindustries.com/gol;
try_files $uri $uri/ /index.html =404;
}
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 /var/www/morderindustries.com/public;
}
}
With this setup, https://morrder.com works fine and serves the website that is located in the /public folder.
I expect https://morrder.com/gol to serve the second website in the /gol folder, but the result is the following:
Does anyone have a clue as to what I've screwed up?

Nginx configuration issue with https on windows

I am trying to deploy my react app to nginx server. Http configuration is working fine, but https is not working. Here is my configuration file.
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name example.com;
root D:\\path-to-build\\build;
index index.html;
location / {
try_files $uri /index.html =404;
}
}
server {
listen 443 ssl;
server_name example.com;
keepalive_timeout 70;
ssl_certificate C:\\Certbot\\live\\domain\\fullchain.pem;
ssl_certificate_key C:\\Certbot\\live\\domain\\privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
#...
access_log D:\\path-to-log\\access.log;
error_log D:\\path-to-log\\error.log;
root D:\\path-to-build\\build;
index index.html;
location / {
try_files $uri /index.html =404;
}
}
}
Your config file looks good. But in your SSL server config i do not see any reference to root or index directives.
Add this to your SSL server as well:
root D:\\path-to-build\\build;
index index.html;
Also as the error implice ("The connection has timed out") can you please try changing the value to keepalive_timeout 70s; Note that the default value is 75 seconds.
Configuration is correct only, but in my server machine 443 post is not open for outside. That's the reason I am getting connection timed out.

How to redirect all http requests to https using nginx for react

Here is my Nginx config for my react app
server {
listen 8080 ssl default_server;
listen [::]:8080 ssl default_server;
listen 443 ssl;
listen [::]:443 ssl;
# ssl on;
ssl_certificate /etc/letsencrypt/live/website.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/website.com/privatekey.pem;
root /home/ubuntu/project-folder/dist/;
index index.html index.htm index.nginx-debian.html;
server_name _;
error_page 404 /index.html;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
}
}
The SSL is enabled it working for https://website.co:8080 but not working on https://website.co and how to redirect if an HTTP request comes? how to handle?

Nginx Rewrite 414-URI Too Large

I am trying to setup CakePHP on an nginx server. Following their blog tutorial on setting up URL rewriting for nginx, I ended up with this in my sites-available/default file:
server {
listen 80;
server_name localhost;
rewrite ^(.*) localhost$1 permanent;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name localhost;
root /usr/share/nginx/html/StudentRecords/webroot;
index index.php index.html index.htm;
error_page 404 /404.html;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
/usr/share/nginx/html/StudentRecords/ is the top directory for my CakePHP app.
When I go to the URL localhost, it shows me the default "Welcom to nginx" page. If I try to go to localhost/StudentRecords/webroot, I get a 414 error, and end up with a URL like this:
http://localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/localhost/StudentRecords/webroot/
I'm having trouble understanding why the server root doesn't point to StudentRecords/webroot, and why my url is multiplying like that.
just remove the first server block
It looks like the rewrite ^(.*) localhost$1 permanent; line (and first code block) was unnecessary. Removing the first block, as well as clearing my browser cache has resolved both issues.

Resources