dockerfile解决nignx镜像部署vue刷新404

dockerfile解决nignx镜像部署vue刷新404,第1张

问题描述

由于安全问题,客户现场的同事部署的Docker环境,nginx部署vue刷新404,这个问题在nginx 修改配置文件很简单的问题,由于本人也没有真正的接触过docker,我们这个边提出让他修改nginx的config 配置,对方提出修改docker 去解决这个问题。
一下是解决方案,我也是刚接触docker文件,先模仿学习,等以后经验多一点在分享个人想法。
https://blog.csdn.net/qq1304530241/article/details/123820143

FROM nginx:latest
MAINTAINER iron.guo
VOLUME /tmp
ENV LANG en_US.UTF-8
RUN echo "server {  \
                    listen       80; \
                    #解决Router(mode: 'history')模式下,刷新路由地址不能找到页面的问题 \
                    location / { \
                        root   /var/www/html/; \
                        index  index.html index.htm; \
                        if (!-e \$request_filename) { \
                            rewrite ^(.*)\$ /index.html?s=\ last; \
                            break; \
                        } \
                    } \
                    access_log  /var/log/nginx/access.log ; \
                } " > /etc/nginx/conf.d/default.conf \
    &&  mkdir  -p  /var/www \
    &&  mkdir -p /var/www/html

ADD ./ /var/www/html/
EXPOSE 80
1.nginx解决刷新404

worker_processes auto;
events {
	worker_connections 1024;
}
http {
	include             mime.types;
	default_type        application/octet-stream;
	sendfile            on;
	keepalive_timeout 65;
	client_max_body_size 20m;
	server {
		listen       80;
		server_name  localhost;
		location / {
			root /usr/share/nginx/html; 		#配置Vue项目根路径
			index index.html index.html; 		#配置首页
			try_files $uri $uri/ /index.html; 	#防止刷新报404
		}
		error_page 500 502 503 504 /50x.html;
			location = /50x.html {
			root html;
		}
	}
}
2.nginx解决刷新404

server
{
    listen 80;
    server_name testwx.wangshibo.com;
 
    #vue-router配置
    location / {
        try_files $uri $uri/ @router;
        index index.html;
    }
    location @router {
        rewrite ^.*$ /index.html last;
    }

3.nginx解决刷新404
server {  
                    listen       80; 
                    #解决Router(mode: 'history')模式下,刷新路由地址不能找到页面的问题 
                    location / { 
                        root   /var/www/html/; 
                        index  index.html index.htm; 
                       	if (!-e $request_filename) {
          					rewrite ^(.*)$ /index.html?s= last;
          					break;
      					}
                    } 
                    access_log  /var/log/nginx/access.log ; 
                }

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1320465.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-11
下一篇 2022-06-11

发表评论

登录后才能评论

评论列表(0条)

保存