Express不在public subdir

时间:2018-05-10 15:51:37

标签: javascript html apache express

我在尝试使用Express和Apache在公共子目录中提供静态文件时遇到了一些问题。 我的工作路径如下:

  • 公共
    • CSS
      • 的style.css
  • app.js

app。 js文件:

var express = require('express');
var app = express();
app.use('/', express.static(__dirname + '/public'));

如果风格。 css在公共文件夹里面一切都很好。如果我将它移动到css目录(更改相对的html标记),这就是我得到的错误:

https://example.com/css/style.css 404 not found

这是html文件中的链接

<link rel="stylesheet" href="css/style.css" type="text/css">

这是我的apache服务器配置:

<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>

这可能是代理问题吗?

1 个答案:

答案 0 :(得分:0)

正如我所料,是Apache配置问题。一旦我编辑了如下所示的配置文件,就可以正确识别公共目录及其子目录“css”。

<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>

相关问题