Home > Web Front-end > uni-app > How to deploy UniApp to Alibaba Cloud CentOS

How to deploy UniApp to Alibaba Cloud CentOS

PHPz
Release: 2023-04-17 13:48:01
Original
1120 people have browsed it

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.

  1. Preparation

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
Copy after login

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
Copy after login
  1. Compile UniApp project

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
Copy after login

After execution, a dist directory will be generated, which contains the compiled static files.

  1. Configuring nginx

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;
    }
}
Copy after login

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
Copy after login
  1. Start UniApp

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 .
Copy after login

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.

  1. Access

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:

  1. Install Node.js, npm and nginx.
  2. Compile the UniApp project and upload the generated static files to the server.
  3. Configure nginx.
  4. Install the static file server serve on the server and use it to start UniApp.
  5. Access your application.

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template