nginx 不会将根目录更改为子目录

nginx won't change root to sub directory

我是 nginx 的新手,我正在尝试让我的 second.domain.com 显示 first.domain.com/dir 的内容,(端口 3000 上的 运行在我的本地主机上)在网上查看后,这似乎是解决方案

# this one works fine
server {
    listen 80;

    server_name first.domain.com;

    location / {
         proxy_pass http://localhost:3000;
         proxy_http_version 1.1;
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection 'upgrade';
         proxy_set_header Host $host;
         proxy_cache_bypass $http_upgrade;
    }
 }

# this one doesn't work as expected
server {
    listen 80;

    server_name second.domain.com;

    location / {
         proxy_pass http://localhost:3000;
         proxy_http_version 1.1;
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection 'upgrade';
         proxy_set_header Host $host;
         proxy_cache_bypass $http_upgrade;
         root /dir;
         index index.html;
    }
 }

但是当我访问 second.domain.com 时,我得到的是与 first.domain.com 相同的根,而不是 first.domain.com/dir ...任何人都可以看到我做错了吗?

借鉴了 mim 的评论,我是这样工作的

# this one is now working as planned :)
server {
    listen 80;

    server_name second.domain.com;

    location / {

         # added mim's suggestiong here
         rewrite /folder/(.*) / break; 

         # then added the folder after the port 
         proxy_pass http://localhost:3000/folder;

         proxy_http_version 1.1;
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection 'upgrade';
         proxy_set_header Host $host;
         proxy_cache_bypass $http_upgrade;
         root /dir;
         index index.html;
    }
 }