我在一臺虛擬機(jī)上(同一個(gè)IP)搭建了LNMP環(huán)境,然后部署兩個(gè)網(wǎng)站(兩個(gè)域名),分別時(shí)www.iwwenbo.com,www.weiyanzixun.com,域名解析正常,同時(shí)開啟了https證書?,F(xiàn)在的問題是我訪問www.iwwenbo.com這個(gè)域名時(shí),經(jīng)常會跳轉(zhuǎn)到www.weiyanzixun.com這個(gè)域名上,請問我的配置問題出在哪里?
環(huán)境:
nginx version: nginx/1.12.1
兩個(gè)域名的nginx配置文件分別如下:
server{
listen 80;
server_name iwwenbo.com www.iwwenbo.com;
add_header Strict-Transport-Security max-age=15768000;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name iwwenbo.com www.iwwenbo.com;
index index.php index.html index.htm;
root /usr/share/nginx/html;
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
ssl_certificate /etc/letsencrypt/live/iwwenbo.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/iwwenbo.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 60m;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
}
server{
listen 80;
server_name weiyanzixun.com www.weiyanzixun.com;
#告訴瀏覽器有效期內(nèi)只準(zhǔn)用 https 訪問
add_header Strict-Transport-Security max-age=15768000;
#永久重定向到 https 站點(diǎn)
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name weiyanzixun.com www.weiyanzixun.com;
index index.php index.html index.htm;
root /usr/share/nginx/weiyanzixun;
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
ssl_certificate /etc/letsencrypt/live/weiyanzixun.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/weiyanzixun.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 60m;
location / {
try_files $uri $uri/ /index.php?$args; #修改內(nèi)容
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#修改此處內(nèi)容支持php
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
}
請哪位大神告訴我問題出在哪里,還有就是這個(gè)配置有那些地方可以進(jìn)行優(yōu)化的?
您location并沒有指定root(文件目錄),以下是我的個(gè)人服務(wù)器上的配置,供您參考:
server {
listen 80;
server_name *.sosout.com;
if ($host ~* "^(.*?)\.sosout\.com$") {
set $domain $1;
}
location / {
if ($domain ~* "blog") {
root /mnt/html/blog;
}
if ($domain ~* "strap") {
root /mnt/html/vueStrap;
}
if ($domain ~* "admin") {
root /mnt/html/admin;
}
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
access_log /mnt/logs/nginx/access.log main;
}
不同的域名指向了不同的目錄。
這個(gè)配置沒有問題,建議檢查是否有瀏覽器緩存。
另外建議用curl或者瀏覽器的開發(fā)者工具禁用緩存來測試
http的配置可優(yōu)化:
server {
listen 80;
server_name www.iwwenbo.com iwwenbo.com;
return 301 https://$server_name$request_uri;
}
樓主的https裸域是301跳轉(zhuǎn)到www的,所以http的配置建議把www放在裸域的前面,減少一次跳轉(zhuǎn)$server_name
只能獲取到server_name
指令的第一個(gè)域名
去掉add_header Strict-Transport-Security max-age=15768000;
,所有瀏覽器在http協(xié)議下都是忽略這個(gè)頭部的,這個(gè)頭部只有在https協(xié)議下才有效
如果需要添加只能添加到https里面
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
北大青鳥中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團(tuán)創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機(jī)構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團(tuán),成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項(xiàng)目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團(tuán)項(xiàng)目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗(yàn),技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點(diǎn)難點(diǎn)突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗(yàn)。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。