Nginx do Nodejs (Express and other general) reverse proxy

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.