/etc/nginx/sitesavailable/default
),将以下内容粘贴到文件中:,,“,location / {, try_files $uri $uri/ /index.php?$query_string;,},,location ~ .php$ {, include snippets/fastcgiphp.conf;, fastcgi_pass unix:/var/run/php/php7.4fpm.sock;,},,location ~ /.ht {, deny all;,},
“,,保存文件并重启Nginx服务。你应该可以在浏览器中访问Laravel应用程序了。在Nginx中运行PHP框架Laravel的配置文件分享如下:
安装Nginx
1、安装命令:
“`shell
brew install nginx
“`
2、启动Nginx服务:
“`shell
sudo nginx
“`
3、测试Nginx是否安装成功:
“`shell
curl IL http://127.0.0.1:8080
“`
修改Nginx配置文件
1、编辑主配置文件:
“`shell
vim /usr/local/etc/nginx/nginx.conf
“`
2、添加以下内容到nginx.conf文件中:
“`nginx
worker_processes 1;
error_log logs/error.log debug;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octetstream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
log_format main ‘$remote_addr $remote_user [$time_local] "$request" ‘
‘$status $body_bytes_sent "$http_referer" ‘
‘"$http_user_agent" "$http_x_forwarded_for"’;
access_log /usr/local/etc/nginx/logs/access.log main;
fastcgi_connect_timeout 3000;
fastcgi_send_timeout 3000;
fastcgi_read_timeout 3000;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
sendfile on;
keepalive_timeout 65;
index index.html index.php;
include sitesenabled/*;
}
“`
添加服务站点配置
1、编辑站点配置文件:
“`shell
vim /usr/local/etc/nginx/sitesenabled/your_site
“`
2、添加以下内容到站点配置文件中:
“`nginx
server {
listen 80;
server_name your_domain.com;
root /path/to/your/laravel/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ .php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.2fpm.sock; #根据实际情况调整路径和版本号
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
“`
配置PHPFPM文件
1、编辑PHPFPM配置文件:
“`shell
vim /usr/local/etc/nginx/conf.d/phpfpm
“`
2、添加以下内容到PHPFPM配置文件中:
“`nginx
location ~ .php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000; # 根据实际PHPFPM监听地址调整
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
“`
检查配置并重启Nginx
1、检查配置文件的正确性:
“`shell
sudo nginx t
“`
2、重启Nginx以使配置生效:
“`shell
sudo nginx s reload
“`
FAQs常见问题解答
1、问题1:如何确认Nginx和PHPFPM已经正确配置?
解答:你可以通过访问配置的域名,查看是否能正常显示Laravel欢迎页面来确认,如果看到“You have arrived”页面或其他预期的输出,说明配置正确,可以查看Nginx和PHPFPM的日志文件以确保没有错误。
2、问题2:如果修改了Nginx配置文件后无法正常访问网站怎么办?
解答:确保配置文件语法正确,使用nginx t
命令进行验证,检查Nginx和PHPFPM服务是否正常运行,使用systemctl status nginx
和systemctl status phpfpm
命令查看服务状态,查看Nginx和PHPFPM的日志文件,通常位于/var/log/nginx/
和/var/log/phpfpm/
目录下,查找可能的错误信息并进行相应修正。
原创文章,作者:未希,如若转载,请注明出处:https://www.kdun.com/ask/1100716.html
本网站发布或转载的文章及图片均来自网络,其原创性以及文中表达的观点和判断不代表本网站。如有问题,请联系客服处理。
发表回复