多二级/三级域名多服务nginx配置
常用命令
1 2 3 4 5 6 7 8
| /usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
|
nginx.conf
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
pid /usr/local/nginx/conf/nginx.pid;
error_log /usr/local/nginx/logs/error.log crit;
worker_processes 24;
worker_rlimit_nofile 65535;
events { use epoll; worker_connections 65535; }
http { include mime.types; default_type application/octet-stream;
access_log off; server_tokens off; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k;
sendfile on; tcp_nopush on; keepalive_timeout 120; tcp_nodelay on;
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; gzip_vary on;
add_header P3P "CP=CAO PSA OUR";
ssi on; ssi_silent_errors on; ssi_types text/shtml; ssi_types text/action;
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwarded_for'; log_format mlnormal '$remote_addr|$remote_user|[$time_local]|$host|"$request"|' '$status|$body_bytes_sent|"$http_referer"|' '"$http_user_agent"|$http_x_forwarded_for|' '$upstream_addr|$upstream_status|$upstream_response_time|' '$server_addr'; include vhost/*.conf; }
|
子配置目录vhost/*.conf
,支持多个域名对应服务的配置文件,一个服务对应一个二级域名文件
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
upstream webcs { ip_hash; server 134.175.14.8:8042 max_fails=2 fail_timeout=30s; server 134.175.151.120:8043 max_fails=2 fail_timeout=30s; }
server { listen 80; server_name outtest.iexxk.com; index index.htm index.html index.jsp; root /data/web/webcs;
access_log /usr/local/nginx_logs/login.access.log mlnormal;
location ~ ^/WEB-INF/* { deny all; }
location ~ .(svn|git|cvs) { deny all; }
location ~.*\.(jsp|do|shtml)?$ { proxy_pass http://webcs; proxy_next_upstream http_500 http_502 http_503 http_504 error timeout invalid_header; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; }
location ~* \.(gif|jpg|jpeg|png|bmp|swf|js|css)$ { expires 30d; } }
|
配置ssl/https
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| upstream res { ip_hash; server 172.16.16.8:14081 max_fails=2 fail_timeout=30s; server 172.16.16.8:14081 max_fails=2 fail_timeout=30s; }
server { listen 80; listen 443 ssl; server_name outtest.res.suresvip.com;
ssl on; ssl_certificate /usr/local/nginx/ssl/1_outtest.res.suresvip.com_bundle.crt; ssl_certificate_key /usr/local/nginx/ssl/2_outtest.res.suresvip.com.key; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; ssl_prefer_server_ciphers on;
access_log /usr/local/nginx_logs/login.access.log mlnormal;
location ~ ^/WEB-INF/* { deny all; }
location ~ .(svn|git|cvs) { deny all; }
location ~.* { proxy_pass http://res; proxy_next_upstream http_500 http_502 http_503 http_504 error timeout invalid_header; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; }
location ~* \.(gif|jpg|jpeg|png|bmp|swf|js|css)$ { expires 30d; } }
|
本地https配置
1 2 3 4 5 6 7 8 9 10
| server { listen 9600 ssl; server_name localhost; ssl_certificate server.crt; ssl_certificate_key server.key; ssl_session_timeout 5m; location / { proxy_pass http://bpf_pf_access; } }
|
tomcat测试https
settings->Automatically follow redirects->Default: Settings->general->ssl certificate verification(off)->certificates->client certificates(添加证书文件即可)
nginx域名验证
阿里云申请证书
选择文件验证,下载文件复制类容
在nginx添加如下
1 2 3 4 5 6 7 8 9 10
| server { listen 80; server_name iexxk.com; location ^~/.well-known/pki-validation/fileauth.txt { add_header Content-Type 'text/html; charset=utf-8'; return 200 '202207310000001mwx2sk9p9akvj3vg3b8sqew1uxxxxxxxxxx0f01ri34uddzzc'; } }
|
点击验证,验证通过后,等待审核通过
下载nginx证书文件
上传证书文件到nginx服务器,配置nginx证书文件
1 2 3 4 5 6 7
| server{ listen 443 ssl; server_name iexxk.com; ssl_certificate /etc/nginx/ssl/8218253_prd-gva.mh.xxx.com.cn_nginx/8218253_iexxk.com.pem; ssl_certificate_key /etc/nginx/ssl/8218253_prd-gva.mh.xxx.com.cn_nginx/8218253_iexxk.com.key; ... }
|