將nginx.conf文件放在根目錄下
在配置nginx的時候,最主要的是server部分:

image.png
nginx配置中路由跳轉(zhuǎn)問題解決:
try_files $uri /index.html;
如果不加這一句,在路由跳轉(zhuǎn)的時候會有問題
其余配置可參考以下源碼:
worker_processes auto;
daemon off;
error_log stderr;
events {
worker_connections 2048;
}
http {
access_log off;
default_type application/octet-stream;
include mime.types;
sendfile on;
keepalive_timeout 20;
client_header_timeout 20;
client_body_timeout 20;
reset_timedout_connection on;
send_timeout 20;
gzip on;
tcp_nopush on;
port_in_redirect off;
server_tokens off;
server {
listen 8080;
server_name localhost;
location / {
root /usr/share/nginx/html;
try_files $uri /index.html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}