nginx 配置 解决 vue history模式下空白 ,以及SSL证书安装

本文详细描述了Nginx服务器的配置,包括SSL设置、虚拟主机、PHP处理和Vue.js开发中的组件规范,以及如何优化HTTPS性能和处理Vue项目结构。还提及了前端面试题和项目实战相关资源。
摘要由CSDN通过智能技术生成
#access_log  logs/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;




# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#    listen       8000;
#    listen       somename:8080;
#    server_name  somename  alias  another.alias;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}


# HTTPS server
#
#server {
#    listen       443 ssl;
#    server_name  localhost;

#    ssl_certificate      cert.pem;
#    ssl_certificate_key  cert.key;

#    ssl_session_cache    shared:SSL:1m;
#    ssl_session_timeout  5m;

#    ssl_ciphers  HIGH:!aNULL:!MD5;
#    ssl_prefer_server_ciphers  on;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}



# HTTPS server   //自定义HTTPS配置
    server { 
        listen 443 ssl; 
        server_name www.55776.club;   #你的域名
        root html; #你的网站根目录
        index index.php index.html index.htm; #网站默认访问文件
        
        ssl_certificate   ../cert/55.crt; 
        ssl_certificate_key  ../cert/55.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        
		location /{
				root   html;
				try_files $uri $uri/ /baiyi/$query_string;
		}

        location ~ \.php(.\*)$  { #HP必须的配置,否则浏览器访问会直接下载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;
		}
}
    
	

server {
    listen 80 ssl;
    server_name www.55776.club;

    #charset koi8-r;
    #access_log  logs/host.access.log  main;
	
	root html/baiyi; #你的网站根目录
	index index.php index.html index.htm; #网站默认访问文件
	
    location / {
        root   html;
        #index  index.html index.htm;
		try_files $uri $uri/ /baiyi/$query_string;
    }
    #error_page  404      /404.html;
    # redirect server error pages to the static page /50x.html
    #
	
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
	
    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT\_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
Vue 编码基础

2.1.1. 组件规范

2.1.2. 模板中使用简单的表达式

2.1.3 指令都使用缩写形式

2.1.4 标签顺序保持一致

2.1.5 必须为 v-for 设置键值 key

2.1.6 v-show 与 v-if 选择

2.1.7 script 标签内部结构顺序

2.1.8 Vue Router 规范

Vue 项目目录规范

2.2.1 基础

2.2.2 使用 Vue-cli 脚手架

2.2.3 目录说明

2.2.4注释说明

2.2.5 其他

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 要在Vue中使用history模式,您需要对Nginx进行配置以正确处理路由请求。 首先,您需要在Vue的路由器中启用history模式,可以通过以下方式完成: ``` const router = new VueRouter({ mode: 'history', routes: [...] }) ``` 然后,在Nginx配置文件中添加以下代码: ``` location / { try_files $uri $uri/ /index.html; } ``` 这将确保当Nginx服务器接收到路由请求时,它将返回Vue应用程序的index.html文件,并允许Vue路由器处理请求。 最后,确保重新加载Nginx服务器以使更改生效: ``` sudo service nginx reload ``` 这样就完成了Vue history模式Nginx配置。现在,您应该能够使用Vue的路由器进行导航,并且当用户刷新页面或直接访问路由时,Nginx将正确地将请求发送到Vue应用程序。 ### 回答2: Vue是基于组件化开发的JavaScript框架,常用于构建单页面应用(SPA)。Vue提供了路由功能,方便前端开发实现页面之间的路由跳转。其中,Vue的路由模式有两种,一种是hash模式,一种是history模式。在hash模式下,URL中带有#号,如http://localhost/#/home,而在history模式下,URL是真实的路径,如http://localhost/home。在实际开发中,history模式更加友好,更符合我们对URL的期望,但需要特殊的nginx配置。 要在Vue中使用history模式,需要先设置VueRouter的mode属性为history。具体方法如下: ``` javascript import Vue from 'vue' import Router from 'vue-router' Vue.use(Router) const router = new Router({ mode: 'history', routes: [...] }) ``` 设置完后,Vue会使用HTML5的History API来实现前端路由。 接下来,我们需要在nginx服务器中进行配置,来支持history模式nginx是一个开源的高性能Web服务器软件,常被用于作为静态资源服务器和反向代理服务器。我们需要在nginx配置文件中添加以下内容: ``` nginx server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html index.htm; try_files $uri $uri/ /index.html; } } ``` 在这里,我们设置了一个nginx的server块,并监听80端口。location /表示匹配到的所有路径,root指定了网站的根目录,index指定默认的访问页面。try_files语句表示当nginx找不到对应的静态资源时,将会跳转到index.html页面,这就是Vue使用history模式所需的。 同时,为了让Nginx生效,我们需要执行以下命令,重新加载nginx配置:sudo nginx -s reload 总结:通过Vuehistory模式,我们可以实现更美观、更友好的URL路径,但需要在nginx服务器中进行配置。通过以上的方法,我们可以轻松实现history模式nginx配置,使我们可以愉快地在Vue中使用history模式了。 ### 回答3: Vue是一款现代化、轻量级且非常有用的前端框架,可以让开发者迅速地创建高质量的单页应用程序。而Vue Router是Vue框架的官方路由管理器,可以帮助我们处理应用程序中的所有路由。 Vue Router支持两种路由模式:Hash模式History模式,其中Hash模式就是默认的模式,而History模式则需要对服务器端和Nginx进行一些配置。 当我们使用Vue Router的History模式时,需要确保我们已经在服务器端正确地配置了路由。这样才能确保我们在浏览器中访问特定页面时,服务器能够正确地响应相关路由。 在Nginx配置Vue Router的History模式非常简单,只需在服务器端的Nginx配置文件中添加以下代码: ``` location / { try_files $uri $uri/ /index.html; } ``` 这段代码的意思是,当请求的URL与文件系统中的文件或目录匹配时,直接返回该文件或目录的内容。如果无法匹配,就返回/index.html中的内容。 这样,当我们在浏览器中访问特定的路由时,Nginx就会返回/index.html的内容,而Vue Router会根据我们的路由配置去渲染对应的组件。这样就能保证Vue Router的History模式正常工作。 总的来说,虽然Nginx配置比较简单,但是我们还是需要正确地配置以确保Vue Router的History模式能够正常运行。只有这样,我们才能在开发原型和生产环境中使用Vue框架和Vue Router,实现快速、高效的前端开发。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值