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?

asked Sep 22, 2020 at 12:11

deathfry's user avatar

deathfrydeathfry

7441 gold badge12 silver badges31 bronze badges

2

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;
    }
 }

answered Sep 22, 2020 at 12:28

Lotttttte's user avatar

2

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)

answered Sep 24, 2020 at 12:34

deathfry's user avatar

deathfrydeathfry

7441 gold badge12 silver badges31 bronze badges

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.

answered Sep 24, 2020 at 12:52

Vijay122's user avatar

Vijay122Vijay122

9648 silver badges13 bronze badges

3

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.