I'm having several problems trying to serve static files in public subdirectories with Express and Apache. My working path is the following:
app. js file:
var express = require('express');
var app = express();
app.use('/', express.static(__dirname + '/public'));
If style. css is inside the public folder everything's fine. If I move it into the css directory (changing the relative html tag), this is the error I get:
https://example.com/css/style.css 404 not found
This is the link in the html file
<link rel="stylesheet" href="css/style.css" type="text/css">
This is my apache server configuration :
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
<Location /*>
ProxyPass http://127.0.0.1:8080
ProxyPassReverse http://127.0.0.1:8080
</Location>
<Directory "/var/www/">
AllowOverride None
Options -Indexes +FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
</IfModule>
Could it be a proxy issue?
As I expected was an Apache configuration issue. As soon as I edit the configuration file as shown below, the public directory and its sub-dir "css" were identified correctly.
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
<Directory "/var/www/">
AllowOverride None
Options -Indexes +FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.