• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Resolved react on nginx page refresh leads to 404

mathi_reg

Basic Pleskian
Hey guys,

I found a little bit online but not the solution to my problem yet.

I'm working on a react native app that is also working as website. All permalinks/urls of the app work just fine and everything checks out. Only problem. When on example.com/something/something and I refresh the page it always results in a 404 page.

What I tried now

I ssh'ed into /var/www/vhosts/system/mydomain.com/conf and udpated the file nginx.conf with


Code:
server {
       location / {
               try_files $uri $uri/ /index.html?$query_string;
       }
}


I restarted the service, however this does not do the trick.

Any idea how to fix that?

Thanks Matt

Here is the full nginx.conf file:

Code:
#ATTENTION!
#
#DO NOT MODIFY THIS FILE BECAUSE IT WAS GENERATED AUTOMATICALLY,
#SO ALL YOUR CHANGES WILL BE LOST THE NEXT TIME THE FILE IS GENERATED.

server {
       listen 175.31.15.213:443 ssl http2;

       server_name example.com;
       server_name www.example.com;
       server_name ipv4.example.com;
       server_name "example.com.52-29-213-14.svr.fm";

       ssl_certificate             /opt/psa/var/certificates/certXTrwD4;
       ssl_certificate_key         /opt/psa/var/certificates/certXTrwD4;
       ssl_client_certificate      /opt/psa/var/certificates/certL2SKRF;

       client_max_body_size 128m;

       root "/var/www/vhosts/example.com/httpdocs";
       access_log "/var/www/vhosts/system/example.com/logs/proxy_access_ssl_log";
       error_log "/var/www/vhosts/system/example.com/logs/proxy_error_log";

       if ($host ~* ^1519\.tirol$) {
               rewrite ^(.*)$ https://www.example.com$1 permanent;
       }

       #extension letsencrypt begin
       location ^~ /.well-known/acme-challenge/ {
               root /var/www/vhosts/default/htdocs;

               types { }
               default_type text/plain;

               satisfy any;
               auth_basic off;
               allow all;

               location ~ ^/\.well-known/acme-challenge.*/\. {
                       deny all;
               }
       }

       #extension letsencrypt end

       location / {
               proxy_pass https://175.31.15.213:7081;
               proxy_set_header Host             $host;
               proxy_set_header X-Real-IP        $remote_addr;
               proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
               proxy_set_header X-Accel-Internal /internal-nginx-static-location;
               access_log off;

       }

       location /internal-nginx-static-location/ {
               alias /var/www/vhosts/example.com/httpdocs/;
               internal;
       }

       location ~ ^/(plesk-stat|awstats-icon|webstat|webstat-ssl|ftpstat|anon_ftpstat) {
               proxy_pass https://175.31.15.213:7081;
               proxy_set_header Host             $host;
               proxy_set_header X-Real-IP        $remote_addr;
               proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
               proxy_set_header X-Accel-Internal /internal-nginx-static-location;
               access_log off;

       }

       location /internal-nginx-static-location/ {
               alias /var/www/vhosts/example.com/httpdocs/;
               internal;
       }

       location ~ ^/(plesk-stat|awstats-icon|webstat|webstat-ssl|ftpstat|anon_ftpstat) {
               proxy_pass https://175.31.15.213:7081;
               proxy_set_header Host             $host;
               proxy_set_header X-Real-IP        $remote_addr;
               proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
               proxy_set_header X-Accel-Internal /internal-nginx-static-location;
               access_log off;

       }

       location ~ ^/~(.+?)(/.*?\.php)(/.*)?$ {
               alias /var/www/vhosts/example.com/web_users/$1/$2;
               fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
               fastcgi_param PATH_INFO $fastcgi_path_info;
               fastcgi_pass "unix:///var/www/vhosts/system/example.com/php-fpm.sock";
               include /etc/nginx/fastcgi.conf;

       }

       location ~ ^/~(.+?)(/.*)?$ {
               proxy_pass https://175.31.15.213:7081;
               proxy_set_header Host             $host;
               proxy_set_header X-Real-IP        $remote_addr;
               proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
               proxy_set_header X-Accel-Internal /internal-nginx-static-location;
               access_log off;
       }

       location ~ \.php(/.*)?$ {
               fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
               fastcgi_param PATH_INFO $fastcgi_path_info;
               fastcgi_pass "unix:///var/www/vhosts/system/example.com/php-fpm.sock";
               include /etc/nginx/fastcgi.conf;

       }

       location ~ /$ {
               index "index.html" "index.cgi" "index.pl" "index.php" "index.xhtml" "index.htm" "index.shtml";
       }

       add_header X-Powered-By PleskLin;

       include "/var/www/vhosts/system/example.com/conf/vhost_nginx.conf";
}

server {
       listen 175.31.15.213:80;

       server_name example.com;
       server_name www.example.com;
       server_name ipv4.example.com;
       server_name "example.com.52-29-213-14.svr.fm";

       client_max_body_size 128m;

       if ($host ~* ^1519\.tirol$) {
               rewrite ^(.*)$ https://www.example.com$1 permanent;
       }

       return 301 https://$host$request_uri;
}

server {
       location / {
               try_files $uri $uri/ /index.html?$query_string;
       }
}
 
Back
Top