Ubantu Configuring Nginx-bound domain names and cooperating with Nodejs

Source: Internet
Author: User
These days in learning js-sdk, I want to achieve in sharing my mobile Web page, can customize the share icon, introduction and other functions. Beginners can only go through the tutorial more.

Incidentally learn the Nginx bound domain name, 1.1 points recorded down, to avoid forgetting later

First of all, this tutorial is very helpful to me: http://www.cnblogs.com/skynet/p/4146083.html

Make sure to install the previous dependency package before Nginx, if you are compiling nginx, use./configure--with-pcre= '/usr/local/src/pcrepath ' so that it can be installed successfully. Access to HTTP://MYVPS_IP will appear welcome to Nginx.

Then the configuration Nginx

Do not bother to unzip the Nginx.config file inside the Nginx, because it is not here after installation.

Under the/etc/nginx directory, the default "soft connection in the Sites-enabled directory, which points to the default file in the Sites-available directory" is the boss of the configuration. To modify:

Add the above server_name:localhost:
root/home/www;
Index index.html;

It means to point the root path to the/home/www directory "Of course you have to mkdir www at home."

Then change the server_name to: my own domain name: like zhidaoer.com

This will allow you to access http://zhidaoer.com and see the Welcom nginx page.

Then just place the HTML file in your own project directory under the/HOME/WWW directory to access the project's page.

And then how to use it with node. js I was referring to this article: Http://stackoverflow.com/questions/5009324/node-js-nginx-what-now,

Basically, just follow this. Create the zhidaoer.com file under Sites-available and copy the relevant code into:

Upstream App_zhidaoer {
Server 127.0.0.1: Start node's port such as 3000;
KeepAlive 8;
}
# The Nginx server instance
server {
Listen 0.0.0.0:80;
server_name zhidaoer.com 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 is 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";
}
}

According to the method of the article to do a soft link, bar their own node project into the/home/www directory, and then NPM install the required package, if the report does not NPM, apt-get install NPM, then NPM install;

Then restart Nginx,/etc/init.d/nginx restart, and start node's www script.

If the node project port is 3000, a page route is Goshop, you can see the page by visiting Http://zhidaoer.com:3000/goshop. Isn't it great!

Then as for the sharing function, today tried to write, but did not take effect, is still looking for reasons. There is a message to keep the record.

The above describes the Ubantu configuration nginx binding domain name and Nodejs, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.