目录
- 1.server模块详解
- 1. 1 listen 80;
- 1. 2 server_name 192.168.1.200 www.myweb.com;
- 1. 3 index index.html index.htm index.jsp;
- 1. 4 root /web/wwwroot/www.myweb.com;
- 1. 5 charset utf-8;
- 1. 6 access_log logs/www.myweb.com.log main;
- 1. 7 ssl on;
- 1. 8 ssl_buffer_size 16k;
- 1. 9 ssl_certificate /etc/skey/a.crt;
- 1. 10 ssl_certificate_key /etc/skey/a.key;
- 1. 11 ssl_session_cache shared:SSL:1m;
- 1. 12 ssl_session_timeout 5m;
- 1. 13 ssl_ciphers HIGH:!aNULL:!MD5;
- 1. 14 ssl_prefer_server_ciphers on;
- 1.15 server_tokens off;
- 1. 16 error_page
- 2. location模块
1.server模块详解
server模块属于HTTP模块下的,用于指定主机和端口。下面为server模块下的参数如下:
server {
listen 80;
server_name 192.168.1.200 www.myweb.com;
index index.html index.htm index.jsp;
root /web/wwwroot/www.myweb.com;
charset utf-8;
access_log logs/www.myweb.com.log main;
ssl on;
ssl_buffer_size 16k;
ssl_certificate /etc/skey/a.crt;
ssl_certificate_key /etc/skey/a.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
error_page 4004 /404.html
error_page 500 502 503 504 /50x.html;
server_tokens off;
location = /50x.html{
root html;
}
1. 1 listen 80;
用于指定虚拟主机的服务端口。
1. 2 server_name 192.168.1.200 www.myweb.com;
用于指定IP地址和域名(需要设置好dns后才能够直接访问),多个域名之间要用空格分开。
1. 3 index index.html index.htm index.jsp;
用于设定访问的默认首页地址。
1. 4 root /web/wwwroot/www.myweb.com;
用于指定虚拟主机的网页根目录,可以是相对路径,也可以是绝对路径。
1. 5 charset utf-8;
设置网页默认的编码格式。
1. 6 access_log logs/www.myweb.com.log main;
用于指定此虚拟机的访问日志路径,最后的main用于指定访问日志输出格式。
1. 7 ssl on;
启用https方式。
1. 8 ssl_buffer_size 16k;
设置用于发送数据的缓冲区大小。
1. 9 ssl_certificate /etc/skey/a.crt;
配置证书crt(pem)保存路径。
1. 10 ssl_certificate_key /etc/skey/a.key;
配置证书key保存路径。
1. 11 ssl_session_cache shared:SSL:1m;
配置加密session重用。
1. 12 ssl_session_timeout 5m;
session超时时间。
1. 13 ssl_ciphers HIGH:!aNULL:!MD5;
指定可用的密码算法,必须是openssl库中指定的方式。
1. 14 ssl_prefer_server_ciphers on;
在使用sslv3或tls协议时,指定服务器密码优先于客户端密码。
1.15 server_tokens off;
禁止在header中出现服务器版本,防止黑客利用版本漏洞攻击。
1. 16 error_page
通过error_page可以定制各种错误信息的返回页面。在默认情况下,nginx在主目录的html目录中查找指定的返回页面。
2. location模块
location作用:基于一个指令设置URL。location是根据URL来进行不同的定位,location可以把平台的不同部分,定位到不同的URL上。一般在配置时,不同的模块会分多个location进行配置,方便区分及修改配置。
location模块在后面的URL重写应用在详细讲解。