Nginx deploys the uniapp project, history mode, opens the page blank, and reports an error: Uncaught SyntaxError: Unexpected token '<'

1. Problem description

nginx deploys uniapp project, history mode, opens blank page, reports error: Uncaught SyntaxError: Unexpected token '<'

This method is basically caused by a wrong configuration.

Two, the solution

Let me tell you about my solution, the steps are as follows:

insert image description here

You need to pay attention to the H5 configuration here. I chose history here, and then filled in a path in the running path, tk, which will be used later. He explained here that if you fill in ./, the default is hash mode. In routing It is useless to select history as the mode. After the two are packaged, the most obvious effect is that the packaged hash can be directly opened and displayed by clicking index.html, and the packaged history can not be displayed by clicking index.html.

For routing mode, you can read this article: https://blog.csdn.net/mashangzhifu/article/details/118416768

then click issue

insert image description here
insert image description here
Click Release, after successful packaging is as follows

insert image description here
Open index.html, you can see the effect

insert image description here
If it is blank, it is history mode. The nginx configuration file is as follows:

server {
    
    
	listen       80;
	server_name  www.xxxx.com;

	#charset koi8-r;

	#access_log  logs/host.access.log  main;

	
	location /prod-api/ {
    
    
		proxy_pass http://localhost:8083/;
	}
	
	location ^~ /tk {
    
    
	  alias  /root/soft/h5/;
	  index  index.html index.htm;
	  try_files $uri $uri/ /index.html last;
	}

	error_page   500 502 503 504  /50x.html;
	location = /50x.html {
    
    
		root   html;
	}
}

Upload the packaged h5 directory to the /root/soft/ directory, then download nginx again, and visit the domain name: http://www.xxx.com/tk to open it successfully

Guess you like

Origin blog.csdn.net/mashangzhifu/article/details/118436989