# 进程启动时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;
}
}
}
nginx配置示例
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 大家好,我是IT修真院成都分院第7期的JAVA学员龚剑飞,一枚正直纯洁善良的java程序员。 今天给大家分享一下,...
- Nginx的配置文件nginx.conf配置详解如下: user nginx nginx ; Nginx用户及组:...