之前:
虽然实现了主页:
但是访问非www的:
还是会访问到访问IP才能看到的主页,显示的OneinStack:
不过访问:
会自动跳转到:
所以感觉是:
用OneinStack新建vhost时,除了www的xxx,没有添加非xxx
根据前段时间的经验,而此处想要解决,应该是去修改nginx配置。
所以去看看
1 2 3 | [root@VM_0_10_centos ~] # nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful |
所以去看看配置文件:
/usr/local/nginx/conf/nginx.conf
1 2 3 4 5 6 7 8 9 10 | server { listen 80; server_name _; access_log /data/wwwlogs/access_nginx .log combined; root /data/wwwroot/default ; index index.html index.htm index.php; ... ########################## vhost ############################# include vhost/*.conf; } |

然后再去看看vhost的配置:
1 2 3 4 5 6 7 8 9 | [root@VM_0_10_centos conf] # cd vhost/ [root@VM_0_10_centos vhost] # ll total 4 -rw-r--r-- 1 root root 1217 Dec 5 22:12 xxx.conf [root@VM_0_10_centos vhost] # sz xxx.conf rz Starting zmodem transfer. Press Ctrl+C to cancel. Transferring xxx.conf... 100% 1 KB 1 KB/sec 00:00:01 0 Errors |
下载下来后,去看看配置:
1 2 3 4 5 6 7 | server { listen 80; listen 443 ssl http2; ... server_name xxx; index index.html index.htm index.php; root /data/wwwroot/xxx ; |

很明显是:
80的http和443的https
的
都是可以打开主页的
-》所以再去加上:
1 | server_name xxx xxx; |

上传上去:
1 2 3 4 5 6 7 8 9 10 11 12 13 | [root@VM_0_10_centos vhost] # mv xxx.conf xxx.conf_backup [root@VM_0_10_centos vhost] # rz rz waiting to receive. Starting zmodem transfer. Press Ctrl+C to cancel. Transferring xxx.conf... 100% 1 KB 1 KB/sec 00:00:01 0 Errors [root@VM_0_10_centos vhost] # ll -lha total 16K drwxr-xr-x 2 root root 4.0K Dec 7 21:16 . drwxr-xr-x 5 root root 4.0K Dec 5 22:12 .. -rw-r--r-- 1 root root 1.2K Dec 7 21:15 xxx.conf -rw-r--r-- 1 root root 1.2K Dec 5 22:12 xxx.conf_backup |
然后再去重新加载nginx:
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 | [root@VM_0_10_centos vhost] # nginx -t nginx: the configuration file / usr / local / nginx / conf / nginx.conf syntax is ok nginx: configuration file / usr / local / nginx / conf / nginx.conf test is successful [root@VM_0_10_centos vhost] # service nginx reload Redirecting to / bin / systemctl reload nginx.service [root@VM_0_10_centos vhost] # service nginx status Redirecting to / bin / systemctl status nginx.service [ 0m nginx.service - nginx - high performance web server Loaded: loaded ( / usr / lib / systemd / system / nginx.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2018 - 12 - 06 22 : 10 : 48 CST; 23h ago Docs: http: / / nginx.org / en / docs / Process: 23309 ExecReload = / usr / local / nginx / sbin / nginx - s reload (code = exited, status = 0 / SUCCESS) Process: 2075 ExecStartPost = / bin / sleep 0.1 (code = exited, status = 0 / SUCCESS) Process: 2065 ExecStart = / usr / local / nginx / sbin / nginx - c / usr / local / nginx / conf / nginx.conf (code = exited, status = 0 / SUCCESS) Process: 1888 ExecStartPre = / usr / local / nginx / sbin / nginx - t - c / usr / local / nginx / conf / nginx.conf (code = exited, status = 0 / SUCCESS) Main PID: 2073 (nginx) CGroup: / system. slice / nginx.service 2073 nginx: master process / usr / local / nginx / sbin / nginx - c / usr / local / nginx / conf / nginx.conf 23311 nginx: worker process Dec 06 22 : 10 : 47 VM_0_10_centos systemd[ 1 ]: Starting nginx - high performance web server... Dec 06 22 : 10 : 48 VM_0_10_centos nginx[ 1888 ]: nginx: the configuration file / usr / local / nginx / conf / nginx.conf syntax is ok Dec 06 22 : 10 : 48 VM_0_10_centos nginx[ 1888 ]: nginx: configuration file / usr / local / nginx / conf / nginx.conf test is successful Dec 06 22 : 10 : 48 VM_0_10_centos systemd[ 1 ]: Started nginx - high performance web server. Dec 07 21 : 17 : 26 VM_0_10_centos systemd[ 1 ]: Reloading nginx - high performance web server. Dec 07 21 : 17 : 26 VM_0_10_centos systemd[ 1 ]: Reloaded nginx - high performance web server. |
然后再去访问:
xxx
然后就可以跳转到www的地址:


【总结】
此处OneinStack添加vhost的xxx,以及加了https
之后访问:
却只是OneinStack的页面
想要访问:
自动跳转到:
的解决办法是:
修改对应的vhost的配置文件:
/usr/local/nginx/conf/vhost/xxx.conf
server_name加上xxx:
1 2 3 4 5 | server { listen 80; listen 443 ssl http2; ... server_name xxx xxx; |
即可。
注意重新加载最新配置:
1 | service nginx reload |