ISPConfig Vhost allows you to clear URLs in Laravel

I have an existing server that works well with multiple sites using nginx and ISPconfig. However, I created a new site and want to use Laravel.

I successfully installed Laravel with the help of a composer and got to the familiar welcome blade displayed when visiting mywebsite.com/public

What I want to do next is make some clean URLs. My experience with vhost files is somewhat limited, and I am having configuration problems.

My routes file looks like this:

Route::get('/', function () { return view('welcome'); }); Route::get('/test', function () { return view('test'); }); 

and I was hoping mywebsite.com/test would display the contents of test.blade.php

I know that I need to do some work with the vhost file before I can expect it to work, but my experience with vhosts is limited and I lost a bit.

My current file is as follows

 server { listen *:80; server_name mywebsite.com ; root /var/www/mywebsite.com/web; index index.html index.htm index.php index.cgi index.pl index.xhtml; error_page 400 /error/400.html; error_page 401 /error/401.html; error_page 403 /error/403.html; error_page 404 /error/404.html; error_page 405 /error/405.html; error_page 500 /error/500.html; error_page 502 /error/502.html; error_page 503 /error/503.html; recursive_error_pages on; location = /error/400.html { internal; } location = /error/401.html { internal; } location = /error/403.html { internal; } location = /error/404.html { internal; } location = /error/405.html { internal; } location = /error/500.html { internal; } location = /error/502.html { internal; } location = /error/503.html { internal; } error_log /var/log/ispconfig/httpd/mywebsite.com/error.log; access_log /var/log/ispconfig/httpd/mywebsite.com/access.log combined; location ~ /\. { deny all; access_log off; log_not_found off; } location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } location /stats/ { index index.html index.php; auth_basic "Members Only"; auth_basic_user_file /var/www/clients/client1/web5/web/stats/.htpasswd_stats; } location ^~ /awstats-icon { alias /usr/share/awstats/icon; } location ~ \.php$ { try_files /5e26a1d85cb98f7191261e023385e60d.htm @php; } location @php { try_files $uri =404; include /etc/nginx/fastcgi_params; fastcgi_pass unix:/var/lib/php5-fpm/web5.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_intercept_errors on; } } 

Now on another server I am working with this simple directive

 server { root /var/www/public; index index.php index.html index.htm; server_name localhost; location / { try_files $uri $uri/ /index.php$is_args$args; } } 

But I'm limited to what I can do with vhost on the current server, since ISPconfig writes most of this for me, and it refuses to write the above configuration, which worked elsewhere. Also I feel that editing the file directly will be bad practice, I will always be on the verge that ISPconfig will overwrite the file for me, so I'm not sure how best to continue this.

My options are just to go and edit vhost and hope for the best, but if I do, how could I make sure ISPconfig cannot overwrite the file without resorting to โ€œhackerโ€ methods?

Alternatively, is there a configuration that I can enter through ISPconfig that allows me to rewrite the correct paths in a way that suits Laravel? In this case, any directive entered must take precedence over the ~ .php $ sentence, as ISPconfig writes, over any directives entered through the control panel.

+4
source share
3 answers

I had the same issue recently. Digging through the sources of ISPConfig, I realized that it can insert / combine / delete the location blocks of this vhosts file by default. So I did the following:

Sites menu> select website> Options

Then I entered the following into the "nginx Directives" field:

 # redirect stuff to the public inner folder location / { root {DOCROOT}/public; try_files /public/$uri /public/$uri/ /public/index.php?$query_string; } # merged the stuff people suggests for laravel inside the php block # mind the 'merge' keyword that did the trick location ~ \.php$ { ##merge## fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_intercept_errors off; fastcgi_buffer_size 16k; fastcgi_buffers 4 16k; } 
+4
source

There is a slight problem with Danilo's answer. Php ran, but assets like js / css / images stopped loading. Adding the following to nginx directives inside ISPConfig works for me:

 location / { root {DOCROOT}/public; try_files $uri public/$uri/ /public/index.php?$query_string; } 
+3
source

I do not understand this, but from my past experience, if I have two domains, I would define server blocks for each of two different files and put them in / etc / nginx / sites -available / site1.com and / etc / Nginx / sites-available / site2.com

but it looks like you already have a website that you are accessing using mywesite.com located at /var/www/mywebsite.com/web; (see the root value of your configuration file)

Now you install Laravel in the test folder in the directory /var/www/mywebsite.com/test.

To access this, you need to try adding the following at the end of the ispconfig file.

Notice how I used the relative path to the laravel public folder from the root of the server block.

 location /../test/public { try_files $uri $uri/ /index.php$is_args$args; } 

For a more detailed guide, try Configuring the Nginx Server Block .

Hope this helps,

TO

+1
source

All Articles