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

Records of using ssh commands on Windows 8

1. Open the virtual machine and git bash window a...

Detailed explanation of MySql installation and login

Check if MySQL is already installed in Linux sudo...

Zabbix configuration DingTalk alarm function implementation code

need Configuring DingTalk alarms in Zabbix is ​​s...

MySQL 8.0.13 installation and configuration graphic tutorial

Msyql database installation, for your reference, ...

My CSS framework - base.css (reset browser default style)

Copy code The code is as follows: @charset "...

CentOS7 upgrade kernel kernel5.0 version

Upgrade process: Original system: CentOS7.3 [root...

A Deeper Look at SQL Injection

1. What is SQL injection? Sql injection is an att...

Summary of Mysql high performance optimization skills

Database Command Specification All database objec...

Briefly understand the MYSQL database optimization stage

introduction Have you ever encountered a situatio...

Implementation of ssh non-secret communication in linux

What is ssh Administrators can log in remotely to...

Detailed examples of replace and replace into in MySQL into_Mysql

MySQL replace and replace into are both frequentl...

About the "occupational disease" of designers

I always feel that designers are the most sensiti...

VSCode configuration Git method steps

Git is integrated in vscode, and many operations ...

The most comprehensive explanation of the locking mechanism in MySQL

Table of contents Preface Global Lock Full databa...