記錄一下,如何配置nodejs nginx的反向代理


本文是在mac下配置nodejs 在nginx下的反向代理

1.安裝nodejs,之前就安裝了。

2.安裝nginx ,我采用的直接源碼安裝

3.進入 /usr/local/nginx/conf 目錄,在該目錄下創建include 文件下,我的配置文件就寫在這個文件夾里面

4.進入 /usr/local/nginx/conf/include 目錄,創建 nginx.node.conf 文件,在里面輸入如下代碼:

upstream nodejs {
    server 127.0.0.1:3000;
    #server 127.0.0.1:3001;
    keepalive 64;
}

server {
    listen 80;
    server_name www.penguu.com penguu.com;
    access_log /var/log/nginx/test.log;
    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;

    }

}

5.進入/usr/local/nginx/conf ,打開nginx.conf, 在http 里面添加 include /usr/local/nginx/conf/include/*

6.重啟nginx , 輸入 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

在瀏覽器輸入penguu.com ok.

 

 


免責聲明!

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



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