Reputation: 1622
I'm new in Nginx.
I built react project so that I can deploy it to a subdirectory.
It works well on local xampp server and All routes works fine.
localhost/mysite.com/public
localhost/mysite.com/public/signup
localhost/mysite.com/public/admin
To host this site, I installed nginx on cloud computer(ubunbu 18.04).
I updated /etc/nginx/sites-available/default
to set server configuration for this project.
my configuration is below
server {
listen 80;
server_name mySite;
root /var/www/html/mysite.com/public;
location / {
try_files $uri $uri/ /index.html;
}
}
Once I try connect site (http://{ip address}/mysite.com/public), it loads first page.
But when I go to sub route, it returns "404 not found".
So I updated server config
server {
listen 80;
server_name mySite;
root /var/www/html/mysite.com/public;
location / {
try_files $uri $uri/ /index.html;
}
location ~ /mysite.com/public {
root /var/www/html/mysite.com/public;
try_files $uri $uri/ /index.html;
}
}
After update this configuration I can't restart nginx due to error.
I think it is because of wrong configuration.
But I can't know the reason due to little knowledge about nginx.
Upvotes: 1
Views: 1609
Reputation: 23259
I got it to work with https://www.resonance.how/resonate-peace/resonate by doing this:
location /resonate-peace/ {
try_files $uri $uri/ /resonate-peace/index.html =404;
}
Upvotes: 1