Home > Article > Backend Development > Ubantu configures nginx to bind domain names and cooperate with nodejs
I have been learning WeChat js-sdk these days. I want to be able to customize the sharing icon, introduction and other functions when sharing my mobile web page. Newbies can only read more tutorials.
I learned nginx binding domain name by the way, and recorded it bit by bit to avoid forgetting it in the future
First of all, this tutorial helped me a lot: http://www.cnblogs.com/skynet/p/4146083. html
Make sure to follow the above steps to install the previous dependency packages of nginx. If you are compiling nginx, use ./configure --with-pcre='/usr/local/src/pcrepath', so that the installation will be successful. . When you visit http://myvps_ip, welcome to nginx.
and then configure nginx
do not bother to unzip the nginx.config file in nginx, because it is not here after installation.
In the /etc/nginx directory, the default [soft link, pointing to the default file in the sites-available directory] in the sites-enabled directory is the configured boss. Make modifications:
Add above server_name: localhost:
root /home/www;
index index.html;
means pointing the root path to the /home/www directory [Of course you have to mkdir www under home first],
Then change the Server_name to: My own domain name: such as zhidaoer.com
In this way, you can visit http://zhidaoer.com and see the welcom nginx page
Then just place it in the /home/www directory HTML file in your own project directory, you can access the project page.
Then how to use it with node.js I refer to this article: http://stackoverflow.com/questions/5009324/node-js-nginx-what-now,
Basically follow this . Create the zhidaoer.com file under sites-available and copy the relevant code into:
upstream app_zhidaoer {
server 127.0.0.1: The port to start the node, 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 be added, see nginx config options location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header -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";
}
}
Make soft links according to the method in the article , put your node project in the /home/www directory, and then npm install the required packages. If there is no npm reported, just apt-get install npm, and then npm install;
The above introduces how ubantu configures nginx to bind domain names and cooperates with nodejs, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.