32 Nginx基础配置实例需求分析
32 Nginx基础配置实例需求分析
32.1 需求分析
(1)有如下访问: http://10.0.0.100:8081/server1/location1 访问的是:index_sr1_location1.html http://10.0.0.100:8081/server1/location2 访问的是:index_sr1_location2.html http://10.0.0.100:8082/server2/location1 访问的是:index_sr2_location1.html http://10.0.0.100:8082/server2/location2 访问的是:index_sr2_location2.html (2)如果访问的资源不存在 返回自定义的404页面 (3)将/server1和/server2的配置使用不同的配置文件分割 将文件放到/home/www/conf.d目录下,然后使用include进行合并 (4)为/server1和/server2各自创建一个访问日志文件
32.2 文件目录
[root@nginx-100 ~]# tree /home/www/ /home/www/ ├── conf.d └── myweb ├── 404.html ├── server1 │ ├── location1 │ │ └── index_sr1_location1.html │ ├── location2 │ │ └── index_sr1_location2.html │ └── logs └── server2 ├── location1 │ └── index_sr2_location1.html ├── location2 │ └── index_sr2_location2.html └── logs 10 directories, 5 files
32.3 备份配置
[root@nginx-100 ~]# cd /usr/local/nginx/conf/ [root@nginx-100 /usr/local/nginx/conf]# mv nginx.conf nginx_1.conf [root@nginx-100 /usr/local/nginx/conf]# cp nginx.conf.default nginx.conf [root@nginx-100 /usr/local/nginx/conf]# ls -ltr total 76 -rw-r--r-- 1 root root 2223 Mar 12 23:40 koi-win -rw-r--r-- 1 root root 3610 Mar 12 23:40 win-utf -rw-r--r-- 1 root root 5231 Mar 12 23:40 mime.types.default -rw-r--r-- 1 root root 5231 Mar 12 23:40 mime.types -rw-r--r-- 1 root root 2837 Mar 12 23:40 koi-utf -rw-r--r-- 1 root root 1007 Mar 12 23:40 fastcgi_params.default -rw-r--r-- 1 root root 1007 Mar 12 23:40 fastcgi_params -rw-r--r-- 1 root root 1077 Mar 12 23:40 fastcgi.conf -rw-r--r-- 1 root root 1077 Mar 12 23:40 fastcgi.conf.default -rw-r--r-- 1 root root 664 Mar 12 23:40 uwsgi_params.default -rw-r--r-- 1 root root 664 Mar 12 23:40 uwsgi_params -rw-r--r-- 1 root root 636 Mar 12 23:40 scgi_params.default -rw-r--r-- 1 root root 636 Mar 12 23:40 scgi_params -rw-r--r-- 1 root root 2656 Mar 12 23:40 nginx.conf.default -rw-r--r-- 1 root root 33 Apr 15 20:00 main.conf -rw-r--r-- 1 root root 3671 May 7 19:01 nginx_1.conf -rw-r--r-- 1 root root 2656 May 8 16:07 nginx.conf
32.4 精简配置
[root@nginx-100 /usr/local/nginx/conf]# cat nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
———————————————————————————————————————————————————————————————————————————
无敌小马爱学习
浙公网安备 33010602011771号