nginx配置-第一篇(基础配置)
2022-01-20 本文已影响0人
响呼雷
忘记出现什么问题了,配置方法1一直报错,改成了方法2就搞定了,因为不了解,所以要去探索。
//方法1
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
//方法2
location ~ \.php(.*) {
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
前提
能够独立配置nginx,都知道nginx配置都可以单独配置在/vhost目录,我们之分析server{}里面的内容。
server {
listen 80; //端口号
server_name 10.70.223.51; //域名或者ip地址
index index.html index.php index.htm; //默认访问页
charset utf-8; //字符集
client_max_body_size 100m; //客服端上传大小限制
root /data/wwwroot/gongzhonghao/public; //项目根目录
# https 配置
#ssl_certificate cert/www.xiaocinao.com.pem;
#ssl_certificate_key cert/www.xiaocinao.com.key;
#ssl_session_timeout 5m;
#ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
#ssl_protocols SSLv3 SSLv2 TLSv1 TLSv1.1 TLSv1.2;
#ssl_prefer_server_ciphers on;
location / {
//伪静态,根据自己项目配置
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
try_files $uri $uri/ =404;
//代理,其实就是一个跳转
#proxy_pass http://域名或者ip;
}
location ~ \.(gif|jpg|png)$ { //文件请求映射目录
root /data/wwwroot/image;
}
location ~ \.php(.*) {
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
//错误日志路径
error_log /data/wwwlogs/gzh.xiaocinao.com.log error;
}