日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

nodejs配置nginx 以后链接mongodb数据库

發布時間:2023/11/27 生活经验 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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就可以了

此時你的網站應該是可以訪問了? 。

?

轉載于:https://www.cnblogs.com/l8l8/p/9355024.html

總結

以上是生活随笔為你收集整理的nodejs配置nginx 以后链接mongodb数据库的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。