nginx ,node 配置項目


nginx ,node 配置項目

1.安裝好node,npm
2.安裝cnpm,-g是全局的

sudo npm install -g cnpm --registry=https://registry.npm.taobao.org

3.通過cnpm安裝擴展(淘寶鏡像安裝會很快)

cnpm install 

4.安裝pm2

sudo cnpm install -g pm2 

5.開啟服務

npm run server

server.js

var express = require('express');
var app = express();
var path = require('path');
var compression = require('compression')

app.use(compression());
app.use("/", express.static(path.join(__dirname, 'Public')));
app.use("/", express.static(__dirname));
app.use("*", function (req, res) {
    res.sendFile(path.join(__dirname, 'html/index.html'));
});


app.listen(7002);

6.編譯項目

npm run start 
$ npm run start 

> snake@1.1.0 start /home/wwwroot/default/taiqi/snake
> export NODE_ENV=dev && atool-build --config webpack.config.dev.js -w --no-compress --devtool "#source-map" -o ./wx_build

📦  1378/1378 build modules
webpack: bundle build is now finished.

7.訪問項目

http://localhost:7002

8.配置nginx

server {
    listen       80;
    server_name  jiqing.snake.com;
    access_log  /home/wwwlogs/access.log;
    location / {
                if ($request_uri ~ ^/api.php/) {
                        proxy_pass http://xxx.snake.com;
                }
                if ($request_uri !~ ^/api.php/) {
                        proxy_pass http://localhost:7002;
                }

        }
}

再配置個域名指向服務器,或者配置個hosts

sudo vim /etc/hosts


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM