The pitfalls of deploying Angular projects in Nginx

The pitfalls of deploying Angular projects in Nginx

Searching online for methods to deploy Angular projects to Nginx after compilation, most articles describe the need to specify a jump to the home page in location of the Nginx configuration file to avoid the problem of 404 caused by refresh. The complete server code is:

server {
 listen 80;
 server_name 192.168.190.131;

 #sendfile on;
 #charset koi8-r;
 access_log /var/log/nginx/host.access.log main;

 location / {
  root /chanchaw/app/angular;
  index index.html index.html;
  try_files $uri $uri/ /index.html;
 }

 error_page 404 /index.html;

 location = /index.html {
  root /chanchaw/app/angular;
 }
}

server_name above is followed by the IP address of CentOS7.3 . Pay special attention to the following location : try_files $uri $uri/ /index.html . This is to prevent 404 errors caused by refreshing the browser. Now here comes the point. After deploying to Nginx , the browser test has the following problems:

index.html and js files are in the same directory, so why can't they be found? chrome is like this, firefox is like this too, okay, let's try IE.

solve

It turns out that chrome and firefox will automatically convert http to https to make requests, and CentOS I used for the experiment was installed in a virtual machine, and I never thought about deploying ssl . Since ie does not convert protocols, there is no problem testing on ie .

You may also be interested in:
  • Record the entire process of Angular project from creation, packaging to nginx deployment

<<:  Detailed explanation of NodeJS modularity

>>:  Example of how to enable Slow query in MySQL

Recommend

Solution to occasional crash of positioning background service on Linux

Problem Description In the recent background serv...

VMware Workstation 14 Pro installation and activation graphic tutorial

This article shares the installation and activati...

How to use negative margin technology to achieve average layout in CSS

We usually use float layout to solve the compatib...

A brief analysis of the use of the HTML webpack plugin

Using the html-webpack-plugin plug-in to start th...

mysql IS NULL using index case explanation

Introduction The use of is null, is not null, and...

25 Tools to Improve Website Usability and Conversion Rates

For a website, usability refers to whether users c...

WeChat applet implements simple calculator function

This article shares the specific code for the WeC...

Implementation of Vue 3.x project based on Vite2.x

Creating a Vue 3.x Project npm init @vitejs/app m...

Making a simple game engine with React Native

Table of contents Introduction Get started A brie...

MySQL sorting using index scan

Table of contents Install sakila Index Scan Sort ...

4 Practical Tips for Web Page Design

Related articles: 9 practical tips for creating we...

Usage and principles of provide and inject in Vue3

Preface: When passing data between parent and chi...