vim /etc/nginx/conf.d/your.conf # 设置后端uwsgi服务器,可写多个用作负载均衡 upstream luffy { server 127.0.0.1:8000; } # 后端 api服务器配置 server { listen 80; server_name api.youdomain.com; location / { include uwsgi_params; uwsgi_pass luffy; } # 加载css、js文件 location ~ .*\.(css|js)$ { root /opt/luffy/luffy/; } } # 前端页面服务器配置 server { listen 80; # 不要怀疑,你没有看错!nginx的80端口可以启动 n 个域名! server_name youdomain.com ; location / { # /opt/luffyweb/dist/ 为npm run build生成的文件夹 root /opt/luffyweb/dist/; index index.html; try_files $uri $uri /index.html; } }
这是最基本配置,其它优化配置就不再赘述!
(2)检查nginx配置文件语法
nginx -t
(3) 启动nginx
systemctl start nginx