Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我有另一个应用程序(不是nginx)在localhost上运行。如何设置nginx,使其在不同的本地IP上运行?_Nginx - Fatal编程技术网

我有另一个应用程序(不是nginx)在localhost上运行。如何设置nginx,使其在不同的本地IP上运行?

我有另一个应用程序(不是nginx)在localhost上运行。如何设置nginx,使其在不同的本地IP上运行?,nginx,Nginx,我有一个应用程序不是在本地主机上运行的nginx。我想在nginx上设置一个服务器,但该服务器不在localhost上运行,因此我可以同时使用它们 我的/etc/hosts文件理想情况下如下所示: 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost 127.0.0.1 a.website.loc 127.0.0.2 another.website.loc server { #

我有一个应用程序不是在本地主机上运行的nginx。我想在nginx上设置一个服务器,但该服务器不在localhost上运行,因此我可以同时使用它们

我的
/etc/hosts
文件理想情况下如下所示:

127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost
127.0.0.1    a.website.loc
127.0.0.2 another.website.loc
server {
    # listen ???;
    server_name another.website.loc;
    root /path/to/another_website;
}
127.0.0.1
是在非nginx应用程序上运行的路由

127.0.0.2
是我希望nginx运行的路线

理想情况下,我的nginx.conf应该是这样的:

127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost
127.0.0.1    a.website.loc
127.0.0.2 another.website.loc
server {
    # listen ???;
    server_name another.website.loc;
    root /path/to/another_website;
}
那么我如何在nginx上设置它呢?或者我也可以在本地主机上设置它,但运行在不同的端口上


谢谢!PS我正在macOS Sierra上运行。

要监听另一个IP,您应该使用另一个IP的网卡

但你必须选择:

  • 修改操作系统主机文件,为服务器分配另一个名称,然后在nginx上

    server {
        server_name yournameonhostsfile
    
  • 使用另一个端口(如您在问题中所述):