vue项目部署到|vue项目部署到 nginx
【vue项目部署到|vue项目部署到 nginx】配置文件:
#usernobody;
worker_processes1;
#error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;
#pidlogs/nginx.pid;
events {
worker_connections1024;
}http {
includemime.types;
default_typeapplication/octet-stream;
#log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
#'$status $body_bytes_sent "$http_referer" '
#'"$http_user_agent" "$http_x_forwarded_for"';
#access_loglogs/access.logmain;
sendfileon;
#tcp_nopushon;
#keepalive_timeout0;
keepalive_timeout65;
#gzipon;
server {
listen80;
server_namelocalhost;
#charset koi8-r;
#access_loglogs/host.access.logmain;
location / {
root/opt/myServe/dist;
indexindex.html index.htm;
try_files $uri $uri/ @router;
#需要指向下面的@router否则会出现vue的路由在nginx中刷新出现404
}#对应上面的@router,主要原因是路由的路径资源并不是一个真实的路径,所以无法找到具体的文件
#因此需要rewrite到index.html中,然后交给路由在处理请求资源
location @router {
rewrite ^.*$ /index.html last;
}location ~ ^/api/ {
rewrite ^/api/(.*)$ /$1 break;
proxy_pass http://ll168.top:9001;
}#error_page404/404.html;
# redirect server error pages to the static page /50x.html
#
error_page500 502 503 504/50x.html;
location = /50x.html {
roothtml;
}# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#proxy_passhttp://127.0.0.1;
#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
#roothtml;
#fastcgi_pass127.0.0.1:9000;
#fastcgi_indexindex.php;
#fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;
#includefastcgi_params;
#}# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#denyall;
#}
}# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#listen8000;
#listensomename:8080;
#server_namesomenamealiasanother.alias;
#location / {
#roothtml;
#indexindex.html index.htm;
#}
#}# HTTPS server
#
#server {
#listen443 ssl;
#server_namelocalhost;
#ssl_certificatecert.pem;
#ssl_certificate_keycert.key;
#ssl_session_cacheshared:SSL:1m;
#ssl_session_timeout5m;
#ssl_ciphersHIGH:!aNULL:!MD5;
#ssl_prefer_server_cipherson;
#location / {
#roothtml;
#indexindex.html index.htm;
#}
#}}
推荐阅读
- vue-cli|vue-cli 3.x vue.config.js 配置
- 2020-04-07vue中Axios的封装和API接口的管理
- Beego打包部署到Linux
- 私有化轻量级持续集成部署方案--03-部署web服务(下)
- 17|17 关山松 第二课作业#公众号项目# D20
- RxJava|RxJava 在Android项目中的使用(一)
- Hacking|Hacking with iOS: SwiftUI Edition - SnowSeeker 项目(一)
- VueX--VUE核心插件
- 靠QQ月入上万灰色暴利偏门的项目
- spring|spring boot项目启动websocket