目录
基本配置
nginx.conf简单配置
#user nobody;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#nginx默认server,测试使用,不需要时可以删除
server {
listen 80;
server_name localhost;
location / {
default_type text/html;
return 200 'This is nginx!';
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
返回指定格式
#返回固定文本
location = /text {
default_type text/html;
return 200 'This is text!';
}
#返回固定json
location = /json {
default_type application/json;
return 200 '{"status":"success","result":"nginx json"}';
}
配置多个conf文件
我的nginx.conf路径:/etc/nginx/nginx.conf
在 /etc/nginx/下创建 conf.d/,用来存 自定义conf文件
在 nginx.conf 加入神秘代码
#修改为auto
worker_processes auto;
http {
server {
......省略......
}
##加入以下神秘代码
include /etc/nginx/conf.d/*.conf;
}
现在,就可以在 conf.d/下自定义 *.conf文件了
server {
listen 80;
server_name 127.0.0.1;
location = /test {
default_type text/html;
return 200 'good';
}
}
OK.