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 下 ...
随机推荐
- February 22nd, 2018 Week 8th Thursday
Confine yourself to the present. 着眼当下. The morning wind spreads its fresh smell, we should get up an ...
- Metasploit渗透测试梗概
1.渗透测试基础内容 https://blog.csdn.net/Fly_hps/article/details/79492646 2.Metasploit基础 https://blog.csdn.n ...
- 为什么react的组件要super(props)
https://segmentfault.com/q/1010000008340434
- 关于折半法查找的一些总结以及ArrayList类的总结
一.折半法查找的总结(这算法很好理解,但我花了好久琢磨他有啥用.....) 1.实际意义 折半法查找主要是为了能够很快在一个数组中找出我们所需要的那个元素,与往常我们通过一个一个比较的方法不同,折半法 ...
- nginx相关命令
https://www.cnblogs.com/zdz8207/p/CentOS-nginx-yum.html
- openvon安装
一.安装环境 1.阿里云centos7 2.关闭防火墙,selinux 临时关闭:setenforce 0 永久关闭:vim /etc/selinux/config 3.修改yum源 1)备份原有的y ...
- 数据库迁移之mysql-redis.txt
一.mysql迁移数据到redis 关于redis+mysql应用: 微博当然是最大的redis集群了: 总结了基本流程: 1. 发微博– > 进入消息队列– > 存入MySQL– > ...
- python:利用logbook模块管理日志
日志管理作为软件项目的通用部分,无论是开发还是自动化测试过程中,都显得尤为重要. 最初是打算利用python的logging模块来管理日志的,后来看了些github及其他人的自动化框架设计,做了个比对 ...
- Cgroups 与 Systemd
Cgroups 是 linux 内核提供的一种机制,如果你还不了解 cgroups,请参考前文<Linux cgroups 简介>先了解 cgroups.当 Linux 的 init 系统 ...
- 为什么大公司一定要使用DevOps?
0 DevOps的意图 究竟什么是DevOps? 要想回答这个问题,首先要明确DevOps这个过程参与的人员是谁?即开发团队和IT运维团队!那么,DevOps的意图是什么呢?即在两个团队之间,建立良好 ...