I have two laravel apps like this:
- apps - dashboard - website
I’m trying to serve them on linux machine, I can’t seem to get them to work together. I want to have two urls like this: 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 }
Advertisement
Answer
I succeeded serving them using another subdomain, the "/dashboard"
idea didn’t work.
I hope someone can suggest the correct way to do it, I would change the accepted answer.
I have now example.com
and admin.example.com
.
Nginx config as below:
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 }
And the second one is:
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 }