与两个单独的域一起运行NodeJs和Apache [英] Run NodeJs and Apache together with two separated domain

查看:134
本文介绍了与两个单独的域一起运行NodeJs和Apache的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有两个域和两个Web应用程序的Linux服务器(VPS),一个使用NodeJS(聊天应用程序)编程,而另一个使用PHP.

I have a Linux server (VPS) with two domains and two web applications, one programmed with NodeJS (chat app) whereas the another is PHP.

因此,我要做的是在同一服务器上的不同域中运行两个应用程序.我尝试了很多方法来执行此操作,但是所有这些方法都可以在单个域和多个URL路径上运行,例如:https://example.com& https://example.com/node.

So, what I want to do is running the two applications in separated domains on the same server. I've tried many methods to do this but all these methods working on single domain and multi URL path like : https://example.com & https://example.com/node.

但是我想要的是这样的:https://nodeappexample.com& https://apacheappexample.com.

But what I want is like this: https://nodeappexample.com & https://apacheappexample.com.

问候

推荐答案

如果您使用的是DigitalOcean等专用服务器或VPS或任何其他服务器,并计划在单个服务器上托管多个网站,则可以通过以下方法来实现Apache HTTP或Nginx Web服务器.

If you are on dedicated or VPS like DigitalOcean or any other server and planning to host multiple websites on a single server then here is how you can do it either with Apache HTTP or Nginx web server.

这假设您已经将DNS映射到您的主机,例如以下两个我已映射到DigitalOcean的域.

This assumes you have already mapped DNS to your host, like following two domains I have mapped to DigitalOcean.

bestflare.com
usefulread.com

在执行此操作之前,请先了解其工作原理.在单个实例上具有多个网站的概念称为虚拟服务器.虚拟服务器配置是在Web服务器配置中定义的,并且基于服务器/IP地址,请求将转发到相应的文档根目录.

Before you implement this, to give you an idea how it works. The concept to have multiple websites on a single instance is called Virtual Server. Virtual server configuration is defined within web server configuration and based on server/IP address, a request is getting forwarded to respective Document Root.

在Apache中配置虚拟主机以托管多个域 登录到Apache HTTP Server 转到apache conf位置. (在默认安装中–您可以在/etc/httpd/conf/httpd.conf中找到它) 备份httpd.conf文件 像下面那样为两个域创建一个VirtualHost容器.

Configure Virtual Host in Apache to host multiple domains Login into Apache HTTP Server Go to apache conf location. ( in default installation – you will find it here /etc/httpd/conf/httpd.conf) Take a backup of httpd.conf file Create a VirtualHost container like below I have done for two domains.

<VirtualHost *:80>
ServerAdmin hello@chandank.com
   DocumentRoot /opt/htdocs/bestflare
   ServerName bestflare.com
   ErrorLog logs/bestflare.com-error_log
   CustomLog logs/bestflare.com-access_log common
</VirtualHost>
<VirtualHost *:80>
   ServerAdmin hello@chandank.com
   DocumentRoot /opt/htdocs/usefulread
   ServerName usefulread.com
   ErrorLog logs/usefulread.com-error_log
   CustomLog logs/usefulread.com-access_log common
</VirtualHost>

注意:根据您的要求更改ServerAdmin,DocumentRoot,ServerName,ErrorLog,CustomLog的值.

Note: Change the value for ServerAdmin, DocumentRoot, ServerName, ErrorLog, CustomLog based on your requirement.

重新启动Apache HTTP并测试两个URL.

Restart Apache HTTP and test both urls.

在Nginx中配置虚拟主机以托管多个域 登录到Nginx服务器 转到virtual.conf位置(在默认位置–您可以在/etc/nginx/conf.d/virtual.conf中找到它) 备份virtual.conf 如下所示,为两个URL创建服务器阻止.

Configure Virtual Host in Nginx to host multiple domains Login into Nginx server Go to virtual.conf location (in default location – you will find it here /etc/nginx/conf.d/virtual.conf) Take a backup of virtual.conf Create server block for both URL’s as I have shown below.

server {
listen 80;
   root /opt/htdocs/bestflare;
index index.html index.htm;
   server_name bestflare.com;
   location / {
       try_files $uri $uri/ =404;
   }
}
server {
   listen 80;
   root /opt/htdocs/usefulread;
   index index.html index.htm;
   server_name usefulread.com;
   location / {
       try_files $uri $uri/ =404;
   }
}

注意:根据您的要求更改root server_name的值.

Note: Change the value for root, server_name based on your requirement.

重新启动Nginx并测试两个URL 那是在单个Web服务器实例(例如Apache或Nginx)中托管多个域的快速指南.网站上线后,请不要忘记对其进行安全性测试.

Restart Nginx and test both URL’s That was the quick guide to hosting multiple domains in single web server instance like Apache or Nginx. Once your website is live, don’t forget to test it against security vulnerabilities.

这篇关于与两个单独的域一起运行NodeJs和Apache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆