nginx部署nodejs前端项目

前端项目打包

下载nodejs

下载地址:https://nodejs.org/en/download/

执行npm -v,查看安装是否成功。

下载nodejs依赖包

在项目目录下执行 npm i

Compiled successfully!

The app is running at:

http://localhost:8007/

项目打包

npm run build

打包后的代码保存在 /dist目录下


linux nginx部署前端项目

配置文件:nginx.conf


nginx部署nodejs前端项目_第1张图片


部署项目的配置在 /conf.d/*.conf

server {
    listen       9898; #监听的端口
    server_name  localhost; #域名
    location / { #/表示匹配目录下所有文件
        root   /home/weblogic/hermes/caxs-mds-front; #打包代码所在目录

    }
}

重启nginx

nginx -s reload

访问服务器域名:9898,即可访问到前端项目的index页面。

windows系统nginx部署前端项目

配置文件:nginx.conf

server {
        listen       8000;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;


        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location / {
            proxy_pass     http://127.0.0.1:8007/;
            proxy_redirect default ;
        }
         location /hermes-web/ {
                   proxy_pass     http://10.10.7.66:8087/hermes-web/;
                   proxy_redirect default ;
               }
    }

重启nginx

nginx.exe -s stop

start nginx.exe



你可能感兴趣的:(nginx部署nodejs前端项目)