地址栏里回车访问就直接404,查询一下资料发现是路由模式的问题
//nginx 配置
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
try_files $uri $uri/ /index.html;#必须要有的
root /home/dist/;#打包后的项目路径,index.html所在文件夹
index index.html index.htm;
}
}
apace 配置
#检查 apache 是否支持mod_rewrite
通过 php 函数 phpinfo() 查看环境配置,在输出的内容中是否存在 mod_rewrite ,存在就不需要进行设置。
如果不存在就在 apache 安装目录中找到 httpd.conf 文件,把 LoadModule rewrite_module 前面的“#”号去掉。
如果没有找到 LoadModule rewrite_module 就添加上 LoadModule rewrite_module modules/mod_rewrite.so ,然后重启 apache 服务
// httpd.conf
Options FollowSymLinks
AllowOverride None
//修改为
Options FollowSymLinks
AllowOverride All
// 修改完重启apache
根目录下 新增 .htaccess 文件
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
记录一下