HTML5 History 模式 即 vue 前后端分离服务端配置

本文档详细介绍了如何配置Vue.js应用在后端服务器上使用HTML5 History模式,包括了针对nginx和Apache服务器的配置示例,以实现SPA(单页应用)的正确路由。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考原文地址

https://router.vuejs.org/zh/guide/essentials/history-mode.html#%E5%90%8E%E7%AB%AF%E9%85%8D%E7%BD%AE%E4%BE%8B%E5%AD%90

1.nginx 配置

server {
        listen       80;
        server_name  nestle.com ;
        root   "D:\install\PHPTutorial\WWW\skscrm\dist";
        location / {
            index  index.html index.htm index.php;
            #autoindex  on;
            try_files $uri $uri/ /index.html;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

2.apache配置

①在vue 编译后的项目下 即默认dist 根目录下 创建一个.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>

② 服务器配置

httpd.conf打开下面配置的注释

LoadModule rewrite_module modules/mod_rewrite.so

然后配置域名位置 在设置成以下内容

<VirtualHost *:80>
    DocumentRoot "D:\install\PHPTutorial\WWW\skscrm\dist"
    ServerName nestle.com
    ProxyPass /api/ http://nestle.com:801/api/
  <Directory "D:\install\PHPTutorial\WWW\skscrm\dist">
      Options FollowSymLinks ExecCGI
      AllowOverride All
      Order allow,deny
      Allow from all
     Require all granted
  </Directory>
</VirtualHost>

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值