nginx的服务配置
1 2 3 4 5 6 7 8 9 10 | vim /usr/local/lnmp/nginx/conf/nginx .conf server { listen 80; server_name www.westos.org; location / { root /www1 ; index index.html; } } |
1 2 3 4 5 6 7 8 | server { listen 80; server_name bbs.westos.org; location / { root /www2 ; index index.html; } |
1 2 3 4 5 6 | mkdir /www1 mkdir /www2 vim /www1/index .html www.westos.org vim /www2/index .html bbs.westos.org |
浏览器上验证:www.westos.org:输出/www1上的发布文件中的目录
bbs.westos.org:输出/www2上的发布文件中的目录
https端口:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | server { listen 443 ssl; server_name www.westos.org; ssl_certificate cert.pem; ssl_certificate_key cert.pem; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { root /www1 ; index index.html index.htm; } } |
1 2 3 4 5 6 7 8 9 | cd /etc/pki/tls/certs/ make cert.pem Country Name (2 letter code) [XX]:cn State or Province Name (full name) []:shaanxi Locality Name (eg, city) [Default City]:xi'an Organization Name (eg, company) [Default Company Ltd]:westos Organizational Unit Name (eg, section) []:linux Common Name (eg, your name or your server's hostname ) []:server7 Email Address []:root@localhost |
1 2 3 | nginx -s reload cp cert.pem /usr/local/lnmp/nginx/conf/ nginx -s reload |
浏览器验证:https://www.westos.org
重定向
1 2 3 4 5 6 7 8 9 10 11 12 | server { listen 80; server_name www.westos.org westos.org bbs.westos.org; rewrite ^(.*)$ https: //www .westos.org permanent; } location / { root /www1 ; index index.html; } } |
主机上输入curl -I www.westos.org 重定向到https://www.westos.org
这种配置在访问网页下的具体页面时会弹出首页,显然这是不合理的
配置如下:
1 2 3 4 5 6 7 8 9 10 11 12 | server { listen 80; server_name www.westos.org westos.org bbs.westos.org; rewrite ^(.*)$ https: //www .westos.org$1 permanent; } location / { root /www1 ; index index.html; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | server { listen 80; server_name www.westos.org westos.org bbs.westos.org; rewrite ^ /bbs $ http: //bbs .westos.org permanent; rewrite ^ /bbs/ (.*)$ http: //bbs .westos.org/$1 permanent; #rewrite ^(.*)$ https://www.westos.org$1 permanent; } #location / { # root /www1; # index index.html; #} } server { listen 80; server_name bbs.westos.org; location / { root /www2 ; index index.html; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | server { listen 80; server_name www.westos.org westos.org bbs.westos.org; #rewrite ^/bbs$ http://bbs.westos.org permanent; #rewrite ^/bbs/(.*)$ http://bbs.westos.org/$1 permanent; #rewrite ^(.*)$ https://www.westos.org$1 permanent; if ($host = "bbs.westos.org" ){ rewrite ^/(.*)$ http: //www .westos.org /bbs/ $1 permanent; } #location / { # root /www1; # index index.html; #} } #server { # listen 80; # server_name bbs.westos.org; # # location / { # root /www2; # index index.html; # } #} } |
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持IT俱乐部。