Ubantu configures nginx binding domain names and cooperation with nodejs

Source: Internet
Author: User
: This article mainly introduces ubantu's configuration of nginx binding domain names and its cooperation with nodejs. if you are interested in PHP tutorials, refer to it. I have been learning js-sdk over the past few days. I want to customize sharing icons and descriptions when sharing my mobile webpage. Cainiao can only go through more tutorials.

I learned how to bind a domain name to nginx. I recorded it at to avoid forgetting it later.

First of all, this tutorial helps me a lot: http://www.cnblogs.com/skynet/p/4146083.html

Make sure that after installing the dependent package before nginx according to the above steps, if nginx is compiled, it will be used. /configure -- with-pcre = '/usr/local/src/pcrepath', so that the installation is successful. When you access http: // myvps_ip, welcome to nginx is returned.

Then Configure nginx

Do not decompress the nginx. config file in nginx because it is not here after installation.

Under the/etc/nginx directory, the default [soft connection, pointing to the default file in the sites-available directory] under the sites-enabled Directory is the configured boss. Modify:

Add:
Root/home/www;
Index index.html;

This means to point the root path to the/home/www Directory [of course, you must first mkdir www under home ],

Change Server_name to my own domain name, for example, zhidaoer.com.

In this way, you can access the http://zhidaoer.com to see the welcom nginx page.

Then, you only need to place the html file in your own project directory under the/home/www directory to access the page of the project.

Then how to use with node. js I am referring to this article: http://stackoverflow.com/questions/5009324/node-js-nginx-what-now,

Just follow this. Create the zhidaoer.com file under sites-available and merge the relevant code:

Upstream app_zhidaoer {
Server 127.0.0.1: port used to start a node, such as 3000;
Keepalive 8;
}
# The nginx server instance
Server {
Listen 0.0.0.0: 80;
Server_name zhidaoer.com;
Access_log/var/log/nginx/zhidaoer. log;
# Pass the request to the node. js server with the correct headers
# And much more can be added, see nginx config options
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_pass http://zhidaoer.com /;
Proxy_redirect off;
# Echo added the following
Proxy_http_version 1.1;
Proxy_set_header Upgrade $ http_upgrade;
Proxy_set_header Connection "upgrade ";
}
}

Follow these steps to make a soft link, put your node project in the/home/www directory, and then npm install the required package. If no npm is reported, apt-get install npm, then npm install;

Restart nginx,/etc/init. d/nginx restart, and then start the node www script.

If the node project Port is 3000 and a page route is goshop, you can see the page by accessing the http://zhidaoer.com: 3000/goshop. Is it great!

As for the sharing function, I tried to write it today, but it has not yet taken effect. I am still looking for reasons. Record the message again.

The above introduces ubantu's configuration of nginx binding domain names and its cooperation with nodejs, including some content, and hope to help friends who are interested in PHP tutorials.

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.