1.在终端执行sudo apt-get update
2.使用apt-get安装nginx:sudo apt-get install nginx
3.安装成功后在终端执行 cd /etc/nginx/sites-available
到sites-available目录下
4.执行sudo gedit local-dev
创建local-dev文件并将如下代码复制进去(注:需将下面代码中的/opt/recruiting-system/
替换成自己想要配置的项目路径,不知道路径,在项目跟目录下执行pwd
进行查看)
server {
location / {
alias /opt/recruiting-system/web/public/assets/;
}
location /fs/ {
alias /opt/recruiting-system/assembly/nginx/files;
}
location /teacher-admin-web {
root /opt/recruiting-system/teacher-admin-web/public/assets;
rewrite '^(.*)$' '/index.html' break;
}
location ~ "^/teacher-admin-web(.*)\.(js|css|map|png|woff|woff2|ttf|jpg)$" {
root /opt/recruiting-system/teacher-admin-web/public/assets;
rewrite ^/teacher-admin-web/(.*)$ /$1 break;
}
location /api {
proxy_pass http://localhost:3000;
rewrite /api/(.+)$ /$1 break;
}
}
5.在sites-available目录下执行cd ../sites-enabled
到sites-enabled 目录下
6.在sites-enabled 目录下执行ln -s /etc/nginx/sites-available/local-dev .
将local-dev链接到当前目录
7 .执行ll
或ls
可以看到在sites-enabled 目录下,除local-dev外还有一个default是可用的,所有,执行sudo rm default
删掉多余的default
- 执行
sudo nginx -t
进行检查,然后执行sudo nginx -s reload
对nginx进行reload