版权声明:本文为博主原创文章,未经博主允许不得转载。作者:沙师弟专栏 https://blog.csdn.net/u014597198/article/details/82702212
安装Nginx默认的配置文件路径:
/usr/local/nginx/conf/nginx.conf
默认的ngnix.conf:
user nobody;
worker_processes 8;
pid log/nginx.pid;
events {
use epoll;
worker_connections 100000;
}
worker_rlimit_nofile 100000;
http {
include mime.types;
default_type application/octet-stream;
server_tokens off;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 0;
fastcgi_connect_timeout 30;
fastcgi_send_timeout 30;
fastcgi_read_timeout 30;
fastcgi_buffer_size 1k;
fastcgi_buffering off;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml text/javascript;
gzip_vary on;
charset utf-8;
access_log off;
log_not_found off;
error_page 400 403 405 408 /40x.html ;
error_page 500 502 503 504 /50x.html ;
server {
listen 80;
server_name aaicourt.qcloud.com;
client_max_body_size 100M;
root /data/qcloud/proxy/www;
access_log /data/qcloud/proxy/log/weblog/access.log;
error_log /data/qcloud/proxy/log/weblog/error.log;
location / {
index index.php index.html index.htm;
if (-d $request_filename) {
rewrite ^(/.*[^/])$ $1/index.php;
}
}
rewrite ^/([a-zA-Z0-9]+)$ / last;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ voice.cgi {
fastcgi_pass 127.0.0.1:3001;
fastcgi_index index.cgi;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ register.cgi {
fastcgi_pass 127.0.0.1:3002;
fastcgi_index index.cgi;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ inner.cgi {
fastcgi_pass 127.0.0.1:3003;
fastcgi_index index.cgi;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SERVER_NAME $http_host;
include fastcgi_params;
fastcgi_ignore_client_abort on;
fastcgi_connect_timeout 600s;
fastcgi_send_timeout 600s;
fastcgi_read_timeout 600s;
}
location ~ /.svn/ {
deny all;
}
}
}
我们现在开始更改,使此配置文件与更多的配置文件相关联。
主要是跟最后面的include有关,情况nginx.conf
user root;
worker_processes auto;
error_log /var/nginx/logs/error.log;
pid ./nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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/nginx/logs/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /usr/local/nginx/conf/mime.types;
default_type application/octet-stream;
include /usr/local/nginx/conf/conf.d/*.conf;
}
其余的conf,我随便举个例子:
/usr/local/nginx/conf/conf.d
server {
listen 80 default;
server_name localhost;
root /var/www/html/roboot/public/;
index index.html index.php index.htm;
access_log /var/log/nginx/ac_bot.log;
error_log /var/log/nginx/err_bot.log;
# set expiration of assets to MAX for caching
location ~* \.(ico|css|js|gif|jpe?g|png|ogg|ogv|svg|svgz|eot|otf|woff)(\?.+)?$ {
expires max;
log_not_found off;
}
server_tokens off;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location / {
index index.php index.html;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php last;
}
}
}