vps - How to configure nginx for multiple site applications under one domain name?
为情所困
为情所困 2017-05-16 17:20:47
0
2
528

Like this
www.example.com
blog.example.com
But different applications, for example www.example.com is a static page, and blog.example.com is a nodejs application
Can it be done? How to configure it specifically?

为情所困
为情所困

reply all(2)
洪涛

Configure root for the static page and configure the reverse proxy for the application

server {
    listen      80;
    server_name blog.example.com ;    
    
    location  / {    
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-Ip $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_redirect off;
    }
}

server {
    listen      80;
    server_name www.example.com;
    
    location  / {
        root E:/Example/public;        
     }
}
PHPzhong

Configure the virtual host
Post the pseudo code for reference

Add at the end of the server section of the configuration file nginx.conf

include vhost/*.conf;

Create the vhost directory
Create files in the vhost directory, such as www.example.com.conf, blog.example.com.conf
Then make the following configuration

server
{
    listen 80;
    server_name www.example.com;
    index index.php index.html index.htm ;
    root /var/www/www.example.com;
    
    if ( $fastcgi_script_name ~ \..*\/.*php ) {
        return 403;
    }
    
    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Of course, nodejs does not rely on ng. ng specifies the nodejs application folder. Domain name access only triggers initialization, and other communication and explanations are returned to the node service

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!