本文是在mac下配置nodejs 在nginx下的反向代理node
1.安裝nodejs,以前就安裝了。nginx
2.安裝nginx ,我採用的直接源碼安裝瀏覽器
3.進入 /usr/local/nginx/conf 目錄,在該目錄下建立include 文件下,個人配置文件就寫在這個文件夾裏面spa
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/*code
6.重啓nginx , 輸入 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.confserver
在瀏覽器輸入penguu.com ok.blog