Nginx

nginx本地的幾個站點

  • September 23, 2020

如果我想在 3 個站點本地工作

站點 1 站點 2 站點 3

如何配置我的 nginx 和主機?

可用網站:

server_name site1

location / {
           proxy_pass http://127.0.0.1:81;
}

其他網站:

server_name 站點 2

location / {
           proxy_pass http://127.0.0.1:82;
}

server_name 站點 3

location / {
           proxy_pass http://127.0.0.1:83;
}

/etc/主機:

127.0.0.1   site1
127.0.0.1   site2
127.0.0.1   site3

這不起作用,他們將我帶到同一個站點

你為什麼使用proxy_pass指令?

server {
   listen 80;
   root /var/www/site1;
   index index.html index.htm;
   server_name site1.local;

   location / {
       try_files $uri $uri/ =404;
   }
}

server {
   listen 80;
   root /var/www/site2;
   index index.html index.htm;
   server_name site2.local;

   location / {
       try_files $uri $uri/ =404;
   }
}

/etc/主機:

127.0.0.1 site1.local site2.local

另見: https ://www.nginx.com/resources/wiki/start/topics/examples/server_blocks/

引用自:https://serverfault.com/questions/1034965