I have my working Vuejs application and I also have problems when I deploy it to it's production environment. Unfortunately, I can't figure out how the configuration should be setup?
When I go to my application from a web browser (in my case http://10.0.0.4/kommandoran2.0), there are no problems in finding index.html. But linked files in index.html
in subfolders are not found (like javascript files [example http://10.0.0.4/kommandoran2.0/js/example.js
] or style sheets [example http://10.0.0.4/kommandoran2.0/css/example.css
]). I have a 404 error for all .js
and .css
files.
Production environment: My operation system is Ubuntu (on a Raspberry Pi), my web server is nginx. This is where my application files are located in my production environment:
Edit 1 (clarification to where the application files are located):
/home/pi/kommandoran2.0/js/example.js
/home/pi/kommandoran2.0/css/example.css
/home/pi/kommandoran2.0/img/example.jpg
/home/pi/kommandoran2.0/index.html
This is the server block from my nginx configuration file:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name mypi.example.org;
root /var/www/html/;
index index.php index.html index.htm;
location /kommandoran2.0 {
root /home/pi;
index index.html;
try_files $uri $uri/ =404;
#I believe that I need some more configuration in this block but I can't figure out what needs to be done?
}
location /iot {
rewrite ^/iot(.*) $1 break;
proxy_pass "http://127.0.0.1:1880";
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
I believe that my problem is very similar to this one, Nginx 404 for css js files, but I don't understand how I could adapt the solution to my problem.
Edit 2, log and error in browser
This is output from nginx in /var/log/nginx/access.log
(extract, I am trying to browse my application at http://10.0.0.4/kommandoran2.0/
here, see browser further down).
10.0.0.4 - - [31/Oct/2018:12:31:37 +0100] "GET /kommandoran2.0/ HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux armv7l) AppleWebKit/537.36 (KHTML, like Gecko) Raspbian Chromium/65.0.3325.181 Chrome/65.0.3325.181 Safari/537.36"
10.0.0.4 - - [31/Oct/2018:12:31:37 +0100] "GET /kommmandoran2.0/css/app.cb44bddd.css HTTP/1.1" 404 200 "http://10.0.0.4/kommandoran2.0/" "Mozilla/5.0 (X11; Linux armv7l) AppleWebKit/537.36 (KHTML, like Gecko) Raspbian Chromium/65.0.3325.181 Chrome/65.0.3325.181 Safari/537.36"
10.0.0.4 - - [31/Oct/2018:12:31:38 +0100] "GET /kommmandoran2.0/css/chunk-vendors.e084a3f2.css HTTP/1.1" 404 200 "http://10.0.0.4/kommandoran2.0/" "Mozilla/5.0 (X11; Linux armv7l) AppleWebKit/537.36 (KHTML, like Gecko) Raspbian Chromium/65.0.3325.181 Chrome/65.0.3325.181 Safari/537.36"
10.0.0.4 - - [31/Oct/2018:12:31:38 +0100] "GET /kommmandoran2.0/js/chunk-vendors.dcf6e5da.js HTTP/1.1" 404 200 "http://10.0.0.4/kommandoran2.0/" "Mozilla/5.0 (X11; Linux armv7l) AppleWebKit/537.36 (KHTML, like Gecko) Raspbian Chromium/65.0.3325.181 Chrome/65.0.3325.181 Safari/537.36"
10.0.0.4 - - [31/Oct/2018:12:31:38 +0100] "GET /kommmandoran2.0/js/app.96c7cdcf.js HTTP/1.1" 404 200 "http://10.0.0.4/kommandoran2.0/" "Mozilla/5.0 (X11; Linux armv7l) AppleWebKit/537.36 (KHTML, like Gecko) Raspbian Chromium/65.0.3325.181 Chrome/65.0.3325.181 Safari/537.36"
This image depicts the requests made corresponding to log file above:
Question: How should I make Nginx understand the correct path to my /js
and /css
folder?