1.查看nginx地址
bash
nginx -t
nginx -t = 测试配置文件语法 + 检查路径是否正确
- 不会重启 Nginx
- 不会影响正在运行的服务
- 只检查你改的配置对不对
结果:
bash
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
2.使用 vi 打开编辑
比如路径是 /etc/nginx/nginx.conf,输入:
vi /etc/nginx/nginx.conf
按一下键盘上的 i 左下角会出现 -- INSERT --,就可以改了。
修改完成后
- 先按一下
Esc键(必须按) - 输入
:wq - 按 回车
- 重启nginx
bash
nginx -s reload
- 不保存强制退出:
Esc→:q!→ 回车 - 保存并退出:
Esc→:wq→ 回车
3.修改配置
复制一个server,修改前端端口 9081,上传文件地址 /home/knowledgeGraph/kg/dist
bash
server {
listen 9081;
listen [::]:9081;
server_name _;
location / {
root /home/knowledgeGraph/kg/dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass http://localhost:8080/;
proxy_connect_timeout 6000;
proxy_read_timeout 6000;
}
#root /usr/share/nginx/html;
# Load configuration files for the default server block.
#include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
4.上传压缩包
上传压缩包到 /home/knowledgeGraph/kg,然后切换到该目录解压压缩包
bash
unzip dist.zip
重启nginx
bash
nginx -s reload