user nginx; #代表使用的用户 worker_processes auto; #工作衍生进程数,一般代表系统cpu核数一到两倍最好 error_log /var/log/nginx/error.log; #错误日至文件 pid /run/nginx.pid; #设置pid存放路径,pid是控制系统中的一个重要的控制文件 # Load dynamic modules. See /usr/share/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; #设置最大链接数 events { worker_connections 1024; } #网页相关配置 http { #gzip on;开启gizp压缩,设置用户访问时,是否开启压缩功能,提高文件数据传输速度 #chatset gb2312;设置字符编码 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 /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; server { listen 80 default_server;#nginx默认访问端口 server_name _; #root /usr/share/nginx/html; index index.html index.php; root /var/www/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { }
配置php
location ~ .php { #这里php 后面本来有个$ 为了支持thinkphp url模式 而去了
fastcgi_pass 127.0.0.1:9000;#php-fpm的默认端口是9000
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_split_path_info ^(.+.php)(.*)$; #支持thinkphp url 模式
fastcgi_param PATH_INFO $fastcgi_path_info; #支持thinkphp url 模式
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
server {
listen 80; #需要监听的端口
server_name xxx.xxx; #域名
index index.html index.php; #默认访问文件
root /var/www/xxx; #虚拟主机目录
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
gzip on;#开启gizp压缩,设置用户访问时,是否开启压缩功能,提高文件数据传输速度 gzip_min_length 1k;#需要压缩的文件最小1k gzip_buffers 4 16k;#申请内存大小来存储压缩的文件,4个16k的数据流 gzip_http_version 1.1;#gzip技术支持的http版本1.1 #以上为最常用的配置 gzip_vary on;#首先判断客户端是否支持gzip压缩技术,不支持的不就不进行gzip技术压缩
pathInfo
if (!-e $request_filename) { rewrite ^/(.*)$ /index.php/$1 last; }
开启目录访问在对应的sever的location 中添加autoindex on;即可;
编译安装:
下载nginx=>wget http://nginx.org/download/nginx-1.10.2.tar.gz
解压tar -zxvf nginx
编译:./configure --prefix=/etc/nginx安装路径 (如果缺少什么模块或者组建,安装缺少的。需要pcre 先看看系统中有没有安装pcre和pcre-devel,没有就使用yum 安装)
make && make install
完成!
错误:403
最有可能是项目目录没有权限 chmod 755 xxx
开启php 错误提示:1:修改/etc/php.ini 中 display_errors = On;修改/etc/php-fpm.d/www.conf中display_errors = on;重启nginx和php-fpm