Reputation: 53
I have developed a website in laravel and I want to install it on a local machine running nginx as a web server. Here is my config file
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root html;
index index.html index.php;
# Make site accessible from http://localhost/
server_name localhost;
location / {
root html;
index index.php;
}
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME C:/nginx/html/$fastcgi_script_name;
include fastcgi_params;
}
}
When I browse http://localhost/mysite/ it runs C:/nginx/html/mysite/index.php
I want to execute C:/nginx/html/mysite/public/index.php file instead. How i can do that?
Upvotes: 1
Views: 243
Reputation: 45
You have to change only one line: Looks the final code in below
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root C:/nginx/html/mysite/public;
index index.html index.php;
# Make site accessible from http://localhost/
server_name localhost;
location / {
root html;
index index.php;
}
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME C:/nginx/html/$fastcgi_script_name;
include fastcgi_params;
}
}
Please look the code carefully. I have changed ony root html to root C:/nginx/html/mysite/public;
Upvotes: 0
Reputation: 16339
From your Nginx file I will assume your root directory for your project is html
and all your Laravel files are in this directory.
If this is the case then you can either just go to http://localhost/mysite/public
or alter your root
directory in your Nginx configuration to html/public
.
If that doesn't work, set root
to the full path on your local machine to reach the public folder of your Laravel project.
Edit Try:
root /c/nginx/html/mysite/public
OR
root C:/nginx/html/mysite/public
Upvotes: 1
Reputation: 1128
Below is my configuration:
server {
server_name laravel.mydomain;
root /home/me/domain/laravel.mydomain/public/;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*|$);
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
internal;
}
}
Just change root
to where your public
folder is.
try_files
makes sure that everything is served by index.php
which is in the root
path when the file doesn't directly exist on the file system.
Upvotes: 0