Write your own project is always to show people, for testing or online are ultimately deployed to the server, this article is to record how the front-end project deployed to the nginx server

Installing Nginx for Linux (dumb-ass)

Install Nginx using yum in CentOS7

See: CentOS7 using yum to install Nginx

Configuring a Static Server

Include /etc/nginx/conf.d/*.conf; Vue and other related projects can be directly built after the file upload

Create a static resource directory (where users store items)

mkdir /www
Copy the code

FTP upload project to/wwwdirectory

I am using Filezilla SFTP link, after successful connection, select/WWW directory and upload the file to this directory

View the nginx configuration file address

nginx -t
# nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
# /etc/nginx/nginx.conf
Copy the code

Configuring a Static Server

vi /etc/nginx/nginx.conf
Find HTTP # {... }
# insert HTTP {} in parentheses
#, such as:
http{
    # Other code (existing code)
    server {
        listen 80; Port requires server open port
        Domain name binding requires domain name resolution A to be recorded to the server IP address
        server_name music.ncgame.cc; If your domain requires IP access please comment this line and change the port
    
        location / { Listen to the path
            root /www; # / WWW is the directory you just created
            index index.html index.htm; # default entry}}}Copy the code

Restart the nginx

Test whether the configuration file is available
Run the following command to display 'test is successful'
nginx -t


Modify the configuration and reload it to take effect
nginx -s  reload  
# Reopen the log file
nginx -s  reopen   
Copy the code

access

For domain name binding, the domain name resolution A needs to be recorded on the server and directly accessed after IP binding. For domain name binding, the direct IP address: port is ok (but the server needs to open the port).

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; # the domain nameLocation / {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;  # the domain name

    ssl_certificate     /path/xxx.pem Certificate path pem or CRT;
    ssl_certificate_key  /path/xxx.key; # the private keyssl_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; location / {Static server or proxy can be configured}}HTTP automatically jumps to HTTPS
server{
    listen 80;
    server_name blog.ncgame.cc;
    rewrite ^/(.*)$ https://blog.ncgame.cc:443/The $1 permanent;
}
Copy the code

other

Issue with Vue flush blank after access

This may be due to the fact that VurRouter has enabled the HTML5 History mode. For details, see the VurRouter backend configuration example

Try_files $uri $uri/ /index.html;

Ex. :

server {
    listen 80; Port requires server open port
    Domain name binding requires domain name resolution A to be recorded to the server IP address
    server_name music.ncgame.cc; If your domain requires IP access please comment this line and change the port

    location / { Listen to the path
        root /www; # / WWW is the directory you just created
        index index.html index.htm; # default entry
        try_files $uri $uri/ /index.html; }}Copy the code