nginx多域名及https配置全過(guò)程(Tomcat服務(wù)器)
主域名配置


二級(jí)域名配置


詳細(xì)配置
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
server {
# listen 80;
# server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# 主域名配置
server {
listen 80;
server_name 主域名;
index index.html;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
# 二級(jí)域名配置
server {
listen 80;
server_name 二級(jí)域名;
index index.html;
location / {
proxy_pass http://127.0.0.1:8081;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
# 主域名https配置
server {
listen 443 ssl;
server_name 主域名; #網(wǎng)站域名,和80端口保持一致
ssl on;
ssl_certificate E:\2846761.pem; #證書(shū)公鑰
ssl_certificate_key E:\2846761.key; #證書(shū)私鑰
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDH:AESGCM:HIGH:!RC4:!DH:!MD5:!3DES:!aNULL:!eNULL;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://www.bjjkkj.com;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Cookie $http_cookie;
#proxy_cookie_path
chunked_transfer_encoding off;
}
}
# 二級(jí)域名https配置
server {
listen 443 ssl;
server_name 二級(jí)域名; #網(wǎng)站域名,和80端口保持一致
ssl on;
ssl_certificate E:\1684324.pem; #證書(shū)公鑰
ssl_certificate_key E:1684324.key; #證書(shū)私鑰
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDH:AESGCM:HIGH:!RC4:!DH:!MD5:!3DES:!aNULL:!eNULL;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://i.bjjkkj.com;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Cookie $http_cookie;
#proxy_cookie_path
chunked_transfer_encoding off;
}
}
server {
listen 80;
server_name 主域名;
return 301 https://$server_name$request_uri;
}
server {
listen 80;
server_name 二級(jí)域名;
return 301 https://$server_name$request_uri;
}
}
注:
- 查資料的過(guò)程中,有些資料說(shuō)主域名配置https之后,二級(jí)域名會(huì)默認(rèn)為https,配置過(guò)程中始終沒(méi)有配置成功,目前使用的是一個(gè)域名對(duì)應(yīng)一條https證書(shū)。
- 域名配置https時(shí),需下載nginx的證書(shū),且每個(gè)域名都會(huì)對(duì)應(yīng)一套證書(shū)
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
舉例詳解Tomcat與Nginx、Apache的區(qū)別是什么
Nginx和Apache都是廣泛使用的Web服務(wù)器軟件,它們各自具有獨(dú)特的特點(diǎn)和優(yōu)勢(shì),適用于不同的應(yīng)用場(chǎng)景,下面這篇文章主要介紹了Tomcat與Nginx、Apache區(qū)別是什么的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2026-03-03
nginx?location指令(匹配順序匹配沖突)實(shí)戰(zhàn)示例詳解
這篇文章主要介紹了nginx?location指令(實(shí)戰(zhàn)示例匹配順序匹配沖突)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-06-06
nginx 老網(wǎng)站域名重定向到新網(wǎng)站的方法(親測(cè))
本文主要介紹了nginx 老網(wǎng)站域名重定向到新網(wǎng)站的方法,以減少業(yè)務(wù)影響并確保流量導(dǎo)向新域名,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2025-02-02
詳解Nginx虛擬主機(jī)配置中server_name的具體寫(xiě)法
這篇文章主要介紹了Nginx虛擬主機(jī)配置中server_name的具體寫(xiě)法,server_name服務(wù)器名是虛擬主機(jī)中必須配置的重要參數(shù),需要的朋友可以參考下2016-03-03
Nginx反向代理+DNS輪詢(xún)+IIS7.5 千萬(wàn)PV 百萬(wàn)IP 雙線 網(wǎng)站架構(gòu)案例
某公司有一站點(diǎn),一天IP 430W,PV 3100W,之前采用5臺(tái) DELL R610 做NLB,系統(tǒng)2008 IIS7.5.每天高峰期時(shí)都不堪重負(fù).會(huì)出現(xiàn)以下情況2012-11-11
Nginx解決history模式下頁(yè)面刷新404問(wèn)題示例
這篇文章主要為大家介紹了Nginx解決history模式下頁(yè)面刷新404問(wèn)題示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10
nginx+ingress 413問(wèn)題排查過(guò)程
處理413錯(cuò)誤需調(diào)整Nginx的client_max_body_size及Ingress配置,合理設(shè)置body-size,若無(wú)效,檢查后端限制,注意過(guò)大可能影響安全2025-08-08

