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

MySQL starts slow SQL and analyzes the causes

Step 1. Enable MySQL slow query Method 1: Modify ...

Related operations of adding and deleting indexes in mysql

Table of contents 1. The role of index 2. Creatin...

How to install MySQL 8.0 and log in to MySQL on MacOS

Follow the official tutorial, download the instal...

Basic principles of MySQL scalable design

Table of contents Preface 1. What is scalability?...

Installation and daemon configuration of Redis on Windows and Linux

# Installation daemon configuration for Redis on ...

Comparative Analysis of IN and Exists in MySQL Statements

Background Recently, when writing SQL statements,...

Vue Learning - VueRouter Routing Basics

Table of contents 1. VueRouter 1. Description 2. ...

Examples of some usage tips for META tags in HTML

HTML meta tag HTML meta tags can be used to provi...

JavaScript implements bidirectional linked list process analysis

Table of contents 1. What is a doubly linked list...

Mini Program to implement Token generation and verification

Table of contents process Demo Mini Program Backe...

Linux Dig command usage

Dig Introduction: Dig is a tool that queries DNS ...