UniApp is a cross-platform application development framework that supports the development of iOS, Android and various small programs. Alibaba Cloud CentOS is a relatively popular server system. This article will introduce how to deploy UniApp to Alibaba Cloud CentOS.
Before deployment, you need to install Node.js and npm on Alibaba Cloud CentOS. It can be installed through the following command:
sudo yum install nodejs sudo yum install npm
At the same time, nginx also needs to be installed as the web server. You can use the following command to install:
sudo yum install nginx
In the local development environment, we usually start the UniApp project through the npm run serve command. But on the server, since there is no GUI interface, this startup method does not work. Therefore, you need to compile the UniApp project first and upload the generated static files to the server.
In the root directory of the UniApp project, execute the following command to compile:
npm run build
After execution, a dist directory will be generated, which contains the compiled static files.
To host the compiled static files on nginx, you need to configure nginx. In the /etc/nginx/conf.d directory, create a new configuration file, for example called uniapp.conf, enter the following content:
server { listen 80; server_name yourdomain.com; # 你的域名 location / { root /path/to/your/dist; # 静态资源目录 index index.html; try_files $uri $uri/ /index.html; } }
where yourdomain.com is your domain name, /path/ to/your/dist is the directory where you upload static files.
After modifying the newly created configuration file in the /etc/nginx/conf.d directory, execute the following command to make the configuration file take effect:
sudo nginx -s reload
After configuring nginx, you can start UniApp on the server. Enter the compiled static file directory and execute the following command:
npm install -g serve serve -s .
Among them, serve is a static file server that can help us start the local static file service. This command can install serve globally and start the static file service in the current directory.
Finally, enter your domain name (or the IP address of the server) in the browser to access your UniApp application.
Summary:
Deploying UniApp on Alibaba Cloud CentOS requires the following steps:
I hope this article can help developers who want to deploy UniApp on Alibaba Cloud CentOS.
The above is the detailed content of How to deploy UniApp to Alibaba Cloud CentOS. For more information, please follow other related articles on the PHP Chinese website!