1.nginx的配置文件nginx.conf
cd /etc/nginx/
vim nginx.conf
打开后的文件为:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;//所有nginx 的content-type的配置
default_type application/octet-stream;
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;
keepalive_timeout 65;//客户端和服务端超时的时间
#gzip on;
include /etc/nginx/conf.d/*.conf;//子配置文件
}
2.nginx.conf的子配置文件(/etc/nginx/conf.d/*.conf)
cd /etc/nginx/conf.d/
ls
vim default.conf
打开的文件为
server {
listen 80;//server所监听的端口
server_name localhost;//server的服务名,服务用域名方式访问的域名的地址
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {//一个server可以有多个location,location /代表一个server当没有其他的路径的时候默认采用/,访问所有的首页路径或自路径都进入到这个location中进行访问
root /usr/share/nginx/html;//location里面所返回的页面的路径
index index.html index.htm;//定义首页默认访问哪个页面
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 404 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
"default.conf" 45L, 1096C