nginx配置
假设我们要运行一个项目在8080端口
那么我们需要修改一下nginx配置
我们用vim来编辑一下配置文件
vim /etc/nginx/nginx.conf
然后我们找到
server {
listen 8080 default_server;
listen [::]:8080 default_server;
server_name _;
root /usr/share/nginx/index.html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
我们要修改listen端口
修改成8080
然后root根目录要修改成需要指向的根目录
下面加上index index.html index.htm
然后在location里面加上
location / {
try_files $uri $uri/ /index.html;
}
server {
listen 8080;
# server_name your.domain.com;
root /home/root/react-demo/demo;
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;
server {
listen 8080;
# server_name your.domain.com;
root /home/root/react-demo/dist;
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;