nodejs配置nginx 以后链接mongodb数据库
服务器 :windows server2008 R2
反向代理 :nginx 1.15.1 for window 64位
数据库:mongodb 4 64位
使用框架express
首先下载nodejs 在官网或者中文网下载都可以 https://nodejs.org/zh-cn/
然后将写好的项目打包成zip 上传 一定要带上 package.json
这样做可以使用npm install 直接将所有的资源全部加载 。以防出现module 找不到;
注意一点:下载mongodb时 在最后下载时 一定要去掉 可视化管理工具下载
不然你会等很久 如果网不好可能就卡死了。 这时候 需要你关闭下载的进程
如果找不到只能重新启动服务器。
如果没有看懂。直接百度mongodb下载卡死 就好了。
npm是node自带的包管理器。
将node部署到服务器上运行时 。我们需要在

因为我们配置nginx时 ,是需要修改localhost的 所有我们需要写上'127.0.0.1';
在操作数据时,我们也应该修改成

否则会导致数据库链接失败。
接下来我们配置nginx服务
首先下载nginx http://nginx.org/en/download.html 下载最新版本 注意是window版

然后安装nginx。将zip包进行解压 切记不要用鼠标直接去运行nginx.exe。
我在这里需要打开cmd进入改目录下 然后 输入 start nginx或者 start nginx.exe 去运行。
只运行一次就好。如果多次运行会开启多个服务,这是一个大坑。
多开了就任务管理器关掉就好了。
不出意外的话。应该是这样的画面

他和node不一样 运行没有报错就说明已经开启了 但是还是会切回命令行模式。这是正常的。
你如果为了确认是否开启nginx 你可以打开任务管理器在进程里查看

有2个nginx就是正常启动了 ,这时候你可以访问localhost:8080
出现了welcome to nginx 说明启动运行成功。
反向代理配置:nginx.conf文件 这里配置的是 http服务 https 只需要改成 443 端口 就可了
#user nobody;
worker_processes 1; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections 1024;
} http {
include mime.types;
default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; #gzip on; upstream nodejs {
server 127.0.0.1:3000; #你配置的端口
keepalive 64;
} server { listen 80;
server_name www.xiaobaiblog.cn; #你需要解析的域名
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_set_header Connection "";
proxy_pass http://nodejs; } #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;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost; #你的域名 # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#}
}

在云解析 将域名设置指向你的公网ip就可以了
此时你的网站应该是可以访问了 。
nodejs配置nginx 以后链接mongodb数据库的更多相关文章
- nodejs链接mongodb数据库
nodeJs链接mongodb数据库有两种方式,第一种是利用官方自己开发的npm包mongodb链接,第二种是利用第三方npm包mongoose链接:这里如果是window操作系统,建议用mongoo ...
- nodejs学习笔记二——链接mongodb
a.安装mongoose库用来链接mongodb数据库 安装mongodb数据库参考mongodb安装 前言(怨言) 本来是想安装mongodb库来链接mongodb的,命令行到nodejs工程目录: ...
- 在IDEA中用三个jar包链接MongoDB数据库——实现增删改查
安装Robo 3T连接MongoDB数据库教程:https://blog.csdn.net/baidu_39298625/article/details/98845789 使用Robo 3T操作Mon ...
- Nodejs通过账号密码连接MongoDB数据库
转自https://blog.csdn.net/szu_lzz/article/details/77435804#commentBox 1.创建管理员 首先开启Mongo服务,然后切换admin数据库 ...
- nodejs+mysql入门实例(链接到数据库)
//连接数据库 var mysql = require('mysql'); var connection = mysql.createConnection({ host: '******', //数据 ...
- nodejs 初次链接 mongodb 的详细细节
时间 2016-06-2613:05:16 在前端的学习也有一段时间了,学习了html,css,javascript,jqery,ajax,php,mysql,学习了这些,了解了一些皮毛,也没有什么 ...
- mongoVUE破解与配置、Mongodb数据库安装
一.mongoVUE 1.5.3破解: 1) 开始-运行-regedit-搜索:B1159E65-821C3-21C5-CE21-34A484D54444 2.) 然后把1,2,3项数值删除,然后重新 ...
- vue+node+mongoDB 火车票H5(六)---城市列表保存到MongoDB数据库并且启用node.js服务
把车站列表保存到数据库,并且从本地创建服务 node.js创建httpserver 1.搭建基于express的运行环境 全局安装express-gengerator cnpm install -g ...
- ubuntu18.04 安装mongodb并使用Robo 3T连接Mongodb数据库
1.前提: 系统:ubuntu18.04 64位 数据库:mongodb GUI:Robo 3T 2018.3.0 描述: mongodb 安装在局域网内的ubuntu的机子上面, 在win 下 ...
随机推荐
- Servlet中的request与response
了解这方面的知识可以查看以下博客 https://www.cnblogs.com/zhangyinhua/p/7629221.html https://www.cnblogs.com/zhaojian ...
- huapin
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- spring boot监控--actuator
原文地址:http://blog.csdn.net/wh_ouyangshuang/article/details/48048111 spring-boot-actuator模块提供了一个监控和管理生 ...
- UVA1618-Weak Key(RMQ)
Problem UVA1618-Weak Key Accept: 103 Submit: 588Time Limit: 3000 mSec Problem Description Cheolsoo ...
- 【css】怎么让Chrome支持小于12px 的文字
谷歌浏览器Chrome是Webkit的内核,有一个 -webkit-text-size-adjust 的私有 CSS 属性,通过它即可实现字体大小不随终端设备或浏览器影响.CSS样式定义如下:-web ...
- spring boot启动后执行方法
@Componentpublic class InitProject implements ApplicationRunner { private static final Logger logger ...
- 1、原生jdbc连接oracle数据库简单介绍
一.jbdc的常用API1.Connection:数据库的链接对象2.statement:数据库sql执行对象3.preparedStatment:sql的预编译处理对象,是statement子接口4 ...
- docker 8 docker的镜像命令
先回顾一下容器.存储.镜像三者之间的关系. 我们知道docker的logo是一条大鲸鱼背上驮着集装箱.那我们对应到docker如下: 1)蓝色的大海里面------->宿主机系统比如我笔记本wi ...
- oracle SQL 执行进度
SELECT SS.USERNAME, SS.SID, SS.SERIAL#, SS.MACHINE, SS.PROGRAM, SL.OPNAME, SL.TARGET, SL.START_TIME, ...
- Java关键字(三)——static
我们说Java是一种面向对象编程的语言,而对象是把数据及对数据的操作方法放在一起,作为一个相互依存的整体,对同类对象抽象出其共性,便是Java中的类,我们可以用类描述世间万物,也可以说万物皆对象.但是 ...