Practice background

I’m building some front-end projects for a cloud service that need to be deployed and supported for access, and some dependencies want to be able to be downloaded locally for cloud services that don’t need to be downloaded from other dependencies, so it’s time to build a proxy environment, and Nginx is the first choice.

Nginx installation

Prepare the environment before installation

GCC, pcre-devel, zlib-devel, openssl-devel, openssl-devel, GCC, pcre-devel, zlib-devel, openssl-devel

yum -y install pcre-devel zlib-devel openssl openssl-devel
Copy the code

The result is as follows:

Nginx related directives

Check whether nginx is installed

```
 yum search nginx
```
Copy the code

Install nginx

 yum install -y nginx
Copy the code

Example Query the nginx file path

whereis nginx
Copy the code

View the nginx configuration file address

nginx -t
Copy the code

Start Nginx and set the startup to run automatically

systemctl start nginx.service
systemctl enable nginx.service
Copy the code

Installation successful Access

Configuring a Static Server

/etc/nginx/nginx.conf } # insert HTTP {# other code (existing code) server {listen 80; Server_name music.ncgame.cc; Location / {# listen to path root/WWW; # / WWW create directory index index.html index.htm; }}}Copy the code

Restart the nginx

'test is successful' Nginx -t # Reload takes effect after the configuration is modified. Nginx -s reload # Reopen the log file. Nginx -s reopen the log fileCopy the code

Configure the domain name bound to the Node project

Nginx proxy is used to bind domain names

Configuration:

server { listen 80; # port server_name blog.ncgame.cc; # domain location / {proxy_pass http://0.0.0.0:3000; proxy_read_timeout 18000; # set timeout}}Copy the code

HTTPS (SSL) configuration

server { listen 443 ssl; # port server_name blog.ncgame.cc; Ssl_certificate /path/xxx.pem ssl_certificate_key /path/xxx.key; Ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; Ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:! aNULL:! MD5; ssl_prefer_server_ciphers on; }} # HTTP automatically jump to HTTPS server{listen 80; server_name blog.ncgame.cc; rewrite ^/(.*)$ https://blog.ncgame.cc:443/$1 permanent; }Copy the code

Access specific folder contents

For example, if you want to access files in the home folder, you can do the following:Configuration:

location /home {
    alias /home/;
    autoindex on;
}
Copy the code

Others (welcome to add)

Issue with Vue flush blank after access

Try_files $uri $uri/ /index.html; try_files $uri $uri Ex. :

server { listen 80; Server_name music.ncgame.cc; Location / {# listen to path root/WWW; # / WWW create directory index index.html index.htm; Try_files $uri $uri/ /index.html; }}Copy the code