Unable to server static files in both wordpress and nodejs in nginx server simultaneously.

October 15, 2019 2k views
Nginx Node.js WordPress

I am trying to setup a nodejs frontend and a wordpress blog along with it for CMS on Nginx. The wordpress site would run at /blog. My wordpress site is installed in /var/www/wordpress and my nodejs application is installed in /home/Smarsolar/floatingsolar. The problem is I am unable to serve static files in both of them. Its either working in wordpress or in Node server. I am attaching my nginx configuration file Any help would be appreciated.

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/wordpress;
        index index.php index.html index.htm index.nginx-debian.html;

        server_name 52.226.21.217;
        location = /favicon.ico { log_not_found off; access_log off; }
        location = /robots.txt { log_not_found off; access_log off; allow all; }
        location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {


        }

        location / {
        root /home/Smartsolar/floatingsolar;
            proxy_pass http://localhost:3000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;


    }

        location /blog {
                # alias /home/apps/myapp;
                try_files $uri $uri/ /index.php$is_args$args;
        location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
                expires max;
                log_not_found off;
        }
        }

        location ~ \.php$ {
                # If php is updated, should update the fpm php version
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }

}
1 Answer

Hello, @resistikat

As long as the path you have listed is correct this should work. I would recommend checking to ensure that the files and directory will allow the www-data user (which nginx is running as) is able to view files in that location.

Could you please let me know what error you get when you try to load a static file?

Have another answer? Share your knowledge.