【问题标题】:How to serve two laravel apps on 1 domain?如何在 1 个域上提供两个 laravel 应用程序?
【发布时间】:2021-05-24 05:15:31
【问题描述】:

我有两个这样的 laravel 应用:

  - apps
      - dashboard
      - website

我正在尝试在 linux 机器上为它们提供服务,但我似乎无法让它们一起工作。 我想要两个这样的网址: https://test.example.co

https://test.example.co/dashboard

server {
  server_name test.example.co;
  index index.php index.html index.htm index.nginx-debian.html;

  location = / {
       root /var/www/example/apps/website;
       try_files $uri $uri/ /public/index.php;
  }

  location ~ ^/dashboard  {
       root /var/www/example/apps;
       try_files $uri $uri/ /dashboard/public/index.php;
       #try_files $uri $uri/ /index.html;
  }

  location ~ \.php$ {
     include snippets/fastcgi-php.conf;
     fastcgi_pass unix:/run/php/php7.4-fpm.sock;
  }

  location ~ /\.ht {
     deny all;
  }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/test.example.co/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/test.example.co/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    # pass the PHP scripts to FastCGI server listening on /var/run/php7.4-fpm.sock
    location ~ \.php$ {
            try_files $uri /index.php =404;
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
    }

}
server {
    if ($host = test.example.co) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
}

【问题讨论】:

    标签: php linux laravel nginx server


    【解决方案1】:

    如果你这样写代码,你能告诉我结果是什么吗:

      location ~ ^/dashboard  {
           root /var/www/example/apps/dashboard/public;
           try_files $uri $uri/ /index.php;
      }
      location = ~ ^/ {
           root /var/www/example/apps/website/public;
           try_files $uri $uri/ /index.php;
      }
    

    我只是交换它。因此它将搜索仪表板,如果用户不在仪表板中,它将检查根目录。

    【讨论】:

    • 谢谢,不幸的是,configtest 失败了。第二部分
    【解决方案2】:

    我成功地使用另一个子域为他们提供服务,"/dashboard" 的想法没有奏效。 我希望有人能提出正确的方法,我会改变接受的答案。

    我现在有example.comadmin.example.com

    Nginx 配置如下:

    server {
       server_name example.com;
    
       index index.php index.html index.htm index.nginx-debian.html;
       root /var/www/example/apps/website/public;
    
       access_log /var/log/nginx/example_access.log;
       error_log  /var/log/nginx/example_error.log;
       try_files $uri $uri/ /index.php$is_args$args;
       location ~ \.php$ {
         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/run/php/php7.4-fpm.sock;
       }
    
       location ~ /\.ht {
         deny all;
       }
    
        listen [::]:443 ssl ipv6only=on; # managed by Certbot
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    
        # pass the PHP scripts to FastCGI server listening on /var/run/php7.4-fpm.sock
        location ~ \.php$ {
                try_files $uri /index.php =404;
                fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
    
    }
    server {
        if ($host = example.com) {
            return 301 https://$host$request_uri;
        } # managed by Certbot
    
      listen 80 default_server;
      listen [::]:80 default_server;
      server_name example.com;
      return 404; # managed by Certbot
    }
    

    第二个是:

    server {
       server_name admin.example.com;
       index index.php index.html index.htm index.nginx-debian.html;
       root /var/www/example/apps/dashboard/public;
    
       try_files $uri $uri/ /index.php$is_args$args;
    
       access_log /var/log/nginx/example_access.log;
       error_log  /var/log/nginx/example_error.log;
    
       location ~ \.php$ {
         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/run/php/php7.4-fpm.sock;
       }
    
       location ~ /\.ht {
         deny all;
       }
    
       # pass the PHP scripts to FastCGI server listening on /var/run/php7.4-fpm.sock
       location ~ \.php$ {
               try_files $uri /index.php =404;
               fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
               fastcgi_index index.php;
               fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
               include fastcgi_params;
       }
    
       listen 443 ssl; # managed by Certbot
       ssl_certificate /etc/letsencrypt/live/admin.example.com/fullchain.pem; # managed by Certbot
       ssl_certificate_key /etc/letsencrypt/live/admin.example.com/privkey.pem; # managed by Certbot
       include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
       ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    
    }
    server {
        if ($host = admin.example.com) {
            return 301 https://$host$request_uri;
        } # managed by Certbot
        listen 80;
        return 404; # managed by Certbot
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-13
      • 1970-01-01
      • 2010-10-22
      • 2019-04-05
      • 2021-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多