有时候,使用Ngnix重载配置,配置的都不知道配置成啥了
今天想配回去最初的模样,路径配置修改需要注意的地方:
最初若依的项目需要注意的地方:
第一步在vue.config.js文件中将publicPath配置成这样
publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
他说:
例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
就是如果你想在原先域名下多加一个admin,就将
publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
转化为
publicPath: process.env.NODE_ENV === "production" ? "/admin/" : "/admin/",
这样访问登录官网的路径由
域名/ 编程了
域名/admin这种格式了
第二步转变的策略,在router文件中,将index.js转变为
这样转换为原先的模样了
export default new Router({ mode: 'history', // 去掉url中的# // base: "/admin", scrollBehavior: () => ({ y: 0 }), routes: constantRoutes })
他说base:"/admin",要访问到admin就要加上base: "base"
第三步 想修改layout/components/Navbar变回原样就写成这样
location.href = '/index';
第四步 request.js的文件,改成这样就行
location.href = '/index';
第五步,初始配置Ngnix的资料
user www; worker_processes auto; error_log /www/wwwlogs/nginx_error.log crit; pid /www/server/nginx/logs/nginx.pid; worker_rlimit_nofile 51200; events { use epoll; worker_connections 51200; multi_accept on; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; client_max_body_size 100m; #用于tomcat反向代理,解决nginx 504错误 proxy_connect_timeout 7200; #单位秒 proxy_send_timeout 7200; #单位秒 proxy_read_timeout 7200; #单位秒 proxy_buffer_size 16k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k; # ps:以timeout结尾配置项时间要配置大点 server { listen 80; server_name localhost; return 301 https://lingyidianke.com$request_uri; charset utf-8; location / { root /home/myProject/ruoyi-vue/dist; try_files $uri $uri/ /index.html; index index.html index.htm; } # location /admin/ { # alias /home/myProject/ruoyi-vue/dist; # try_files $uri $uri/ /admin/index.html; # index index.html index.html; # } # location @dsrouter { # rewrite ^/(admin)/(.+)$ /$1/index.html last; # } location /prod-api/ { proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://localhost:8083/; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { #SSL 默认访问端口号为 443 listen 443 ssl; #请填写绑定证书的域名 server_name lingyidianke.com; #请填写证书文件的相对路径或绝对路径 ssl_certificate lingyidianke.com_bundle.crt; #请填写私钥文件的相对路径或绝对路径 ssl_certificate_key lingyidianke.com.key; ssl_session_timeout 5m; #请按照以下协议配置 ssl_protocols TLSv1.2 TLSv1.3; #请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。 ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; ssl_prefer_server_ciphers on; charset utf-8; location / { root /home/myProject/ruoyi-vue/dist; try_files $uri $uri/ /index.html; index index.html index.htm; } # location /admin/ { # alias /home/myProject/ruoyi-vue/dist; # try_files $uri $uri/ /admin/index.html; # index index.html index.html; # } # location /admin/ { # alias /home/myProject/ruoyi-vue/dist; # try_files $uri $uri/ @dsrouter; # index index.html; # } # location @dsrouter { # rewrite ^/(admin)/(.+)$ /$1/index.html last; # } location /prod-api/ { proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://localhost:8083/; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
配置这样就重新看见了项目