- 打包好react项目
npm run build
- 安装nginx
sudo apt-get install nginx
- 配置nginx:
vim /etc/nginx/nginx.conf
添加内容如下:
server {
listen 80;
# server_name your.domain.com;
root /home/ubuntu/project/kris_web/build/;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 20M;
keepalive_timeout 10;
}
修改nginx.conf文件第一行为:
user root
重启nginx:
sudo service nginx restart
访问:http://ip:port/