当前位置: 首页 > Web前端 > vue.js

Nginxvue前端分离配置示例

时间:2023-03-31 19:39:22 vue.js

vue+thinkphpvue为历史路径由模型,固定/api,/static前显为php使用server{listen80;服务器名称本地主机;设置$static_root'';#web目录设置$php_root'';#php目录root$static_root;indexindex.htmlindex.htmindex.php;位置~\.php${root$php_root;fastcgi_pass127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;包括fastcgi_params;fastcgi_buffer_size128k;fastcgi_buffers3232k;fastcgi_connect_timeout300;fastcgi_send_timeout300;fastcgi_read_timeout300;}location/{try_files$uri$uri//index.html;}位置^~/api/{root$php_root;if(!-e$request_filename){最后重写^(.*)$/index.php?s=/$1;休息;}}location^~/static/{root$php_root;access_log关闭;}#首页不存在location=/index.html{add_headerCache-Controlno-cache;添加_h标头Pragma无缓存;add_header过期0;}location~*\.(js|css|png|jpg|jpeg|gif|ico)${过期12小时;log_not_found关闭;access_log关闭;}}vue+portforwardinglevel2目录可以使用这个方法server{listen80;服务器名称本地主机;根'';indexindex.htmlindex.htm;位置^~/api/{proxy_set_headerHOST$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;proxy_set_headerX-Forwarded-Proto$scheme;proxy_passhttp://localhost:8080;#proxy_passhttp://localhost:8080/;#转发时如果想去掉/api前缀,可以用这个}location/{try_files$uri$uri//index.html;}#首页不缓存location=/index.html{add_headerCache-Controlno-cache;add_headerPragma无缓存;add_header过期0;}location~*\.(js|css|png|jpg|jpeg|gif|ico)${过期12小时;log_not_found关闭;access_log关闭;}}