Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
778 views
in Technique[技术] by (71.8m points)

reactjs - nginx react deployment forbidden 403

I am trying to deploy a React application to an ubuntu server using nginx.

I started to compile my sources from home folder PUBLIC_URL=/var/www/xxx/build npm run build then, I moved it to /var/www/xxx/build

My /etc/nginx/sites-available/default looks like this:

server {
     listen 80 default_server;
     root /var/www/xxx/build;
     server_name x.x.x.x; #I am hiding my real IP
     index index.html index.htm
     
     location / {
         try_files $uri $uri/ =404;
     }

     location ~ .css {
         alias /var/www/xxx/build/static/css/;
         add_header Content-Type text/css;
     }

     location ~ .js {
         alias /var/www/xxx/build/static/js/;
         add_header Content-Type application/x-javascript;
        
     }


}

Then, I changed the acces directories : chown -R $USER:www-data /var/www/xxx/build And chmod 755 -R /var/www/xxx/build

I maked all directories upto that point executable: chmod +x /var/ chmod +x /var/www/ chmod +x /var/www/xxx/ chmod +x /var/www/xxx/build/ Finally, I did sudo service nginx restart

My problem is that the resources accessible via /var/www/xxx/build/static/ are forbidden when I access my domain, why ?

I am stuck for hours with this problem, I really thank the person who will try to help to solve it !!!

question from:https://stackoverflow.com/questions/65940821/nginx-react-deployment-forbidden-403

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...