今天帮朋友把他的thinkphp5部署到 lnmp上,结果出错了,系统提示模板找不到,后来查资料查看发现tp5
把入口文件放到了public下面,所以在配置路由的时候 你应该把路径配置到public下。这样就不会出现模板
找不到的问题啦!下面时具体的简单配置
一,编辑/etc/nginx/nginx.conf:
user nobody;
worker_processes 1;
events {
worker_connections 10240;
}
http {
include mime.types;
default_type application/octet-stream;
#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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost1;
root /var/www/;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
# root html;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
index index.html index.htm index.php ;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
# root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#可以把这个虚拟主机移动到一个文件夹下,然后用include加载进来,方便后面处理
server {
listen 8090;
# listen somename:8090;
# server_name somename alias another.alias;
root /var/www/test/public;
location / {
# root /var/www/test/pulic;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
index index.html index.htm;
}
location ~ \.php$ {
# root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
#跨域问题
add_header 'Access-Control-Allow-Origin' "*";
add_header 'Access-Control-Allow-Headers' "jwtauthorization";
add_header 'Access-Control-Allow-Headers' "Jwtauthorization";
}
}
include /etc/nginx/webserver/server-lyp_thinkphp5.conf;
}
二,编辑完之后执行:
nginx -t && nginx -s reload #查看配置文件是否出错 并且重新加载nginx
三,把端口加入到防火墙
firewall-cmd --zone=public --add-port=8091/tcp --permanent #把8091端口加入到防火墙 永久
四,重启并且加载防火墙配置
systemctl restart firewalld
注意:如果你是阿里云用户记得把端口加入到安全组,安全组最好加一段区域的端口号,这样就不用每次都
配置安全组。我加的端口范围时8000~9000
网友评论