How to launch an Angular project? Let's talk about the online process with nginx!

青灯夜游
Release: 2022-05-09 10:47:59
forward
2532 people have browsed it

AngularHow to launch the project? The following article will talk about the launch process of Angular project in combination with nginx. I hope it will be helpful to everyone!

How to launch an Angular project? Let's talk about the online process with nginx!

After we complete theangularproject, how should you go online? [Related tutorial recommendations: "angular tutorial"]

Maybe you will answer:

It is not my bussiness. Right?

Indeed, as a pure front-end developer, after completing the development of the project, you do not need to touch the next online content.

However, as a developer, it is very important for us to understand the process of the project from development to launch.

Let’s explain it in combination withnginx.

Same for react and vue

Packaging project

What is used here isangular-cligenerated project. After developing the project, you only need to runnpm run build.builderwill output according to the packaging content you preset inangular.json.

How to launch an Angular project? Lets talk about the online process with nginx!

  • outputPath: The packaged storage folder path
  • index: Mount the template file
  • main: The project's After the main entry file
  • ...

is completed, you can view the packaged file throughoutputPath.

How to launch an Angular project? Lets talk about the online process with nginx!

Install Nginx

We install it on the machine where we want to deploy the code, that is, the serverNginx. The operation is based on theyumsource operation ofcentos.

# 安装nginx yum -y install nginx # 查看版本 nginx -v # 启动nginx systemctl start nginx.service # 访问 默认是80端口 your_ip:80
Copy after login

Configure Nginx

View the configuration filenginx.confofNginx.

Usewhereis nginxto findnginxThe installation location

is in/etc/nginx/conf. Add a new configuration file to the dfolder, such asdemo.conf, and configure the server's interface address and front-end entry file path:

upstream api { server 127.0.0.1:8888; // 服务端 keepalive 2000; } server { listen [::]:80 default_server; server_name _; root /usr/share/nginx/demo-frontend/dist/demo-web; // 前端资源位置 location / { add_header Access-Control-Allow-Origin *; } location /api { // api 处理 proxy_pass http://api; } } # Settings for a TLS enabled server. # server { # listen 443 ssl http2 default_server; # listen [::]:443 ssl http2 default_server; # server_name _; # root /usr/share/nginx/frontend/demo.com/dist; # ssl_certificate "/root/ssh/nginx/1_demo.com_bundle.crt"; # ssl_certificate_key "/root/ssh/nginx/2_demo.com.key"; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 10m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # # Load configuration files for the default server block. # include /etc/nginx/default.d/*.conf; # # location / { #. add_header Access-Control-Allow-Origin *; # } # to api restful service # location /api { # proxy_pass http://api; # } # error_page 404 /404.html; # location = /404.html { # } # error_page 500 502 503 504 /50x.html; # location = /50x.html { # } # }
Copy after login

Code comments Part of TLS is the transport encryption protocolhttps, and the corresponding certificate needs to be added.

In the above code, we store the front-end static resources under/usr/share/nginx/frontend/demo.com/dist/, then we will package Just upload the content underdist/**to this directory file.

/usr/share/nginx/frontend/demo.com/dist/ actually points to the index.html entry file.

A relatively simple upload solution is to execute it directly on the user's local machine:rsync -avzh server username@62.**1.**.**:/usr/share /nginx/frontend/demo.com/dist/ index.html and its similar contents under the /dist project. Synchronize the packaged content to the corresponding location of the remote server. Then restartnginx, that is,nginx -s reloadand you’re done.

How to launch an Angular project? Lets talk about the online process with nginx!

Summary

Let’s summarize the whole process:

  • angular project packaging

  • Server installation nginx

  • nginx processing for back-end services

  • nginx handles front-end content

  • Upload the angular packaging file to the specified location on the server

Of course, you must apply for relevant information in advance The domain name, registration, related certificates, etc.

The idea is that simple. Of course, professional work should be left to operation and maintenance colleagues, don’t be too busy~

Original address: https://juejin.cn/post/7087417501486678030

Author: Jimmy

For more programming-related knowledge, please visit:Programming Teaching! !

The above is the detailed content of How to launch an Angular project? Let's talk about the online process with nginx!. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:juejin.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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!