配置 nginx 以使用 laravel public 文件夹
Configurate nginx to work with laravel public folder
这是我的 nginx.conf 文件:
我创建的配置文件不起作用,它不会转到 http://localhost/api
我的系统是 manjaro
....
http {
....
server {
....
}
include /etc/nginx/sites-enabled/*;
}
我的 laravel 配置文件是:
server {
root /srv/tamsam/public;
index index.php index.html index.htm;
gzip on;
gzip_types text/plain application/xml text/css application/javascript;
gzip_min_length 1000;
location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location /storage {
alias /srv/tamsam/public;
try_files $uri $uri/ @laravelapi;
location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}
location /api {
alias /srv/tamsam/public;
try_files $uri $uri/ @laravelapi;
location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}
location @laravelapi {
rewrite /api/(.*)?$ /api/index.php?$is_args$args last;
}
}
但是 http:///localhost/api 给我错误 404 Not Found
感谢您的帮助,谢谢
看起来你的 @laravelapi
位置配置不正确。
location @laravelapi {
rewrite /api/(.*)$ /api/index.php last;
}
另请检查您的 php 配置
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
fastcgi_param SCRIPT_FILENAME $request_filename;
对它的工作很重要。
这是我的 nginx.conf 文件:
我创建的配置文件不起作用,它不会转到 http://localhost/api 我的系统是 manjaro
....
http {
....
server {
....
}
include /etc/nginx/sites-enabled/*;
}
我的 laravel 配置文件是:
server {
root /srv/tamsam/public;
index index.php index.html index.htm;
gzip on;
gzip_types text/plain application/xml text/css application/javascript;
gzip_min_length 1000;
location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location /storage {
alias /srv/tamsam/public;
try_files $uri $uri/ @laravelapi;
location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}
location /api {
alias /srv/tamsam/public;
try_files $uri $uri/ @laravelapi;
location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}
location @laravelapi {
rewrite /api/(.*)?$ /api/index.php?$is_args$args last;
}
}
但是 http:///localhost/api 给我错误 404 Not Found
感谢您的帮助,谢谢
看起来你的 @laravelapi
位置配置不正确。
location @laravelapi {
rewrite /api/(.*)$ /api/index.php last;
}
另请检查您的 php 配置
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
fastcgi_param SCRIPT_FILENAME $request_filename;
对它的工作很重要。