1.打开nginx的配置文件nginx.conf,可以发现其初始的内容如下:
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; 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 logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; proxy_pass http://192.168.56.202:8080; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root 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; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
... #全局块 events #event块 { ... } http #http块 { ... #http全局块 } server #server块 { ... #server全局块 location [PATTERN] #location块 { ... } location [PATTERN] #location块 { ... } } server #server块 { ... } ... }
全局块:主要设置一些影响服务器整体运行的配置,其作用域是全局的。通常包括服务器
的用户、允许生成的worker process(此配置项一般为服务器主机的核数),nginx的进程pid
的存放路径、日志的存放路径和类型以及配置文件的引入
events块:主要设置一些影响服务器与用户的网路链接的参数,常用的有:是否开启对
多worker process下的网络连接进行序列化、师傅允许同时接收多个网络连接、每个
worker process可以同时支持的最大连接数。
http块:一般配置代理、缓存、日志定义等绝大多少的功能和第三方的配置都在这个模块中设置
server块:与虚拟主机有关
location块:对请求的处理、地址定向、应答控制
以上就介绍了初识nginx配置文件--nginxconf,包括了nginx,配置文件方面的内容,希望对PHP教程有兴趣的朋友有所帮助。