I'm trying to create a landing page with links to php websites demo like the following :
https://demos.infinitywebservices.tn/ : landing page
https://demos.infinitywebservices.tn/demo1/public : takes to demo1 app
https://demos.infinitywebservices.tn/demo2/public : takes to demo2 app
... and so on
I'm using Nginx on Debian 9 Server
My /etc/nginx/sites-available/infinitywebservices.conf
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
root /var/www/tony-projects/infinitywebservices/demos;
index index.php index.html index.htm;
server_name demos.infinitywebservices.tn www.demos.infinitywebservices.tn;
gzip on;
gzip_vary on;
gzip_disable "msie6";
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types
text/plain
text/css
text/js
text/xml
text/javascript
application/javascript
application/x-javascript
application/json
application/xml
application/xml+rss;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|svg|woff|woff2|ttf)\$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
location ~* \.(?:css|js)\$ {
expires 7d;
access_log off;
add_header Cache-Control "public";
}
ssl_certificate /...; # managed by Certbot
ssl_certificate_key /...; # managed by Certbot
}
My Directories structures
/var/www
|__tony-projects
|__infinitywebservices
|__demos
|__ index.php (Landing page for demos.infinitywebservices.tn/)
|__ demo1 (Laravel Project)
|__ demo2 ...
|
|.....
P.S
.htaccess config under demo1 and
demo2 Laravel ProjectsFor now only home page works for me when trying to visit a sub
project like https://demos.infinitywebservices.tn/demo1/public/ (See : https://demos.infinitywebservices.tn/laravel-test/public)
However for
https://demos.infinitywebservices.tn/laravel-test/public/test
(Route test exists) , i'm getting 404 Not Found nginx/1.10.3
What i'm missing here ?
Instead of responding with a 404 status, you need to pass all unknown URIs to the application's controller (e.g. /laravel-test/public/index.php).
If you have multiple apps with a well defined directory structure, you will probably want to use a regular expression to extract the name of the application (e.g. laravel-test) so that the correct controller is used.
For example:
location / {
try_files $uri $uri/ @rewrite;
}
location @rewrite {
rewrite ^(/[^/]+/public) $1/index.php last;
}