First configure the Environment Nginx+nodejs ... (No, please look at my other articles, not repeat here)
CD to Nginx site-available directory Ubuntu in
cd/etc/nginx/site-available/
Create a server file
sudo touch testserver
Then you can copy the following code into it (the industrious coder can write it again)
http{
keepalive 65 ; #超时
gzip on; #是否开启压缩模块 gzip_comp_level 6 ; #压缩比例 1-9 gzip_vary on; #根据http头判断是否进行压缩 gzip_min_length 1000 /plain text/html text/css Application/json application/x-javascript Text/xml application/xhtml application/xml+rss text/javascript image/jpeg image/jpg image/png image/gif; #压缩文件类型 basically all gzip_buffers 16 8k; #向系统申请 8k-based 16 times-fold cache unit
Upstream my_node_app{ #不清楚的推荐看一下 http://nginx.org/en/docs/or poor English can see the article of the Great God http://www.cnblogs.com/taosim/ Articles/3110626.html inside there is a detailed introduction to the upstream server 127.0.0.1:3000; KeepAlive; #超时 }
server{Listen the; #监听80端口 server_name zboy.com; #设置服务名称Location/{#服务是非静态文件, set the reverse proxy Proxy_pass http for the Nodejs service://My_node_app; Proxy_redirect off; Proxy_set_header X-real-IP $remote _addr; Proxy_set_header X-forwarded-For $proxy _add_x_forwarded_for; Proxy_set_header Connection""; } Location~ ^/(img/|js/|css/|images/|flash/|media/) $ {#如果是静态文件 Hijack processing root/home/app/myapp/ Public; Your project URL access_log off; Expires Max; } }}
OK file is done, but the configuration is one step ...
Create a soft link to the Site-enable folder
sudo ln-s/etc/nginx/site-available/testserver/etc/nginx/site-enable/testserver
Then execute the command.
Sudo/etc/init.d/nginx Reload /stop-start
At this point, turn on your Nodejs service note Port number settings 3000
Browser opens http://127.0.0.1
Done! ~
Here I read the article of the predecessor. Address: http://ourjs.com/detail/nodejs-on-nginx-%E4%BD%BF%E7%94%A8nginx%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90% 86%e5%a4%84%e7%90%86%e9%9d%99%e6%80%81%e9%a1%b5%e9%9d%a2
Nginx do Nodejs (Express and other general) reverse proxy