0

good day.

I have a React application on Red Hat server and I have a build/static folder on it (there is no index.html file inside, is it normal?). The task is to make nginx to serve static files on this server.

My config is in conf.d in /etc/nginx folder:

 $ cat my.conf 
server {
    listen 443 http2 ssl;
    listen [::]:443 http2 ssl;
    root /home/***-user/repo/****/frontend/build/static;
    server_name **.***.***.**;
    ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
    ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
    ssl_dhparam /etc/ssl/certs/dhparam.pem;
    location / {
                proxy_pass http://localhost:8080;
    }
}

I restarted nginx and how should I know that all static files are now served by nginx and are working properly?

2

3 Answers 3

0

You should just move in /home/***-user/repo/****/frontend/build/static the index.html (with the js,css...) of your React application.

I don't know if your nginx config works, personally I use this one

server {
    listen       443 ssl;
    server_name  localhost;
    ssl_certificate    /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;

    location / {

        root   /../build/static/;
        index  index.html index.htm;
    }
 }
2
  • index.html is in /home/***-user/repo/****/frontend/public folder and index.js and index.css are in /home/***-user/repo/****/frontend/src folder. Should I move all those 3 files into one /build/static folder?
    – deathfry
    Commented Sep 22, 2020 at 12:37
  • Not necessarily. You just need index.html to be in the folder mentionned in the root attribute in your nginx config
    – Lotttttte
    Commented Sep 22, 2020 at 14:20
0

Well, after doing some research it seems that the way to check if nginx work is to go to our site and switch between links on our site while watching over the network tab. In prev version everytime I visited certain tab it downloaded resources, while now it is downloading resources only on 4-5 switching between tabs (And I don't know why, because I set expires to 15 minutes (expires 15m; in my conf)

0

On your browser, visit your https link, open chrome developer tools, and you could see the static files served once you are in root path /. All the files inside your, /home/-user/repo/*/frontend/build/static will be served upfront on launching the url.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.