php配置nginx

server {
listen 443;
listen 80;
server_name caoleizhen.cn;
root /var/www/thinkphp5.1/public/;
index index.html index.htm index.php;

#ssl
ssl on;
    ssl_certificate  /var/www/thinkphp5.1/extend/1_www.qwer.cn_bundle.crt;
ssl_certificate_key /var/www/thinkphp5.1/extend/2_www.qwer.cn.key;
    ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;

#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;

location / {
if (!-e $request_filename) {
rewrite . /index.php last;
}
}

#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 /usr/share/nginx/html;
}

# 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|\.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;
#}
}

配置完无法访问php文件,可能出现的问题主要在location配置
location ~ \.php|\.html$ {
fastcgi_pass 127.0.0.1:9000;//查看php-fpm是否绑定9000端口
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;//项目root目录是否正确,要写成全局变量,再到location里面,这里就访问不到
include fastcgi_params;
}


猜你喜欢

转载自www.cnblogs.com/colizen/p/10606474.html