# 进程启动时worker数目,建议设置为CPU核数的1~2倍(我的是双核线程的)
worker_processes 4;
# 每个worker最大连接数目,默认是1024
events {
worker_connections 10240;
}
http {
# 包含nginx.conf同目录下的配置文件 'mime.types'
include mime.types;
# 默认的返回类型
default_type application/octet-stream;
# nginx通过使用sendfile指令来控制是不是用linux提供的零拷贝功能,默认是on(开启),否则是off
sendfile on;
# 请求超时时间
keepalive_timeout 65;
# 默认虚拟主机
server {
listen 80;
# 虚拟主机名称
server_name localhost;
location / {
# 虚拟主机根目录
root /home/linzh/workspace/application/public;
# 默认访问的文件
index index.html index.php index.htm;
# 重新规则
if (!-e $request_filename) {
# 访问这些文件夹不重写
rewrite ^/(assets|img|js|css|font)/.* break;
# index.php重写,都懂的
rewrite ^/(.*)$ /index.php/$1 last;
}
}
#错误页面,可以在nginx安装目录下找到这个文件 50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# 访问的文件以.php结尾的,调用php-fpm(注意需要删除".php$"最后的$符号)
location ~ \.php {
# 根目录
root /home/linzh/workspace/application/public;
# php-fpm监听地址
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# 下面两段的作用是支持path_info设置
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
# fastcgi参数
fastcgi_param SCRIPT_FILENAME /home/linzh/workspace/application/public$fastcgi_script_name;
include fastcgi_params;
}
}
# 另一个虚拟主机,配置同上,区别是server_name
server {
listen 80;
server_name demo.me;
location / {
root /home/linzh/workspace/demo/public;
index index.html index.php;
if (!-e $request_filename) {
rewrite ^/(assets|img|js|css|font)/.* break;
rewrite ^/(.*)$ /index.php/$1 last;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php {
root /home/linzh/workspace/demo/public;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME /home/linzh/workspace/demo/public$fastcgi_script_name;
include fastcgi_params;
}
}
}
网友评论