nginx多站点配置

2018-12-17 10:47:02来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

一、安装nginx

https://yq.aliyun.com/articles/101144?spm=5176.10695662.1996646101.searchclickresult.70af967bColksb

二、nginx.conf文件配置

 1 user  root;
 2 worker_processes  1;
 3 
 4 #error_log  logs/error.log;
 5 #error_log  logs/error.log  notice;
 6 #error_log  logs/error.log  info;
 7 
 8 #pid        logs/nginx.pid;
 9 
10 
11 events {
12     worker_connections  1024;
13 }
14 
15 error_log          /usr/local/nginx/logs/error.log debug;
16 
17 http {
18     include       mime.types;
19     default_type  application/octet-stream;
20     
21    underscores_in_headers on;
22        log_format log_req_resp '$remote_addr - $remote_user [$time_local] '
23         '"$request" $status $body_bytes_sent '
24         '"$http_referer" "$http_user_agent" $request_time' 
25      'req_header:"$request_body" req_body:"$request_body"';
26 
27 
28     #access_log  logs/access.log  main;
29 
30     sendfile        on;
31     #tcp_nopush     on;
32 
33 
34     keepalive_timeout  65;
35    
36     #gzip  on;
37 
38     include /usr/local/nginx/conf/conf.d/*.conf;
39  
40 }

/usr/local/nginx/conf/conf.d/shout.conf配置

 1 upstream toshou.top{ 
 2         server blog.toshout.top; 
 3 }
 4 server {
 5     listen       80;
 6     server_name  toshou.top;
 7 
 8     #charset koi8-r;
 9     #access_log  /var/log/nginx/log/host.access.log  main;
10     location / {
11         proxy_pass http://toshou.top;
12         proxy_http_version 1.1;
13         proxy_set_header Host $host;
14         proxy_set_header X-Real-IP $remote_addr;
15         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
16         proxy_set_header Via "nginx";
17     }
18 
19     # redirect server error pages to the static page /50x.html
20     #
21     error_page   500 502 503 504  /50x.html;
22     location = /50x.html {
23         root   /usr/share/nginx/html;
24     }
25 }

绑定域名

shou.top域名绑定到nginx服务ip,访问toshou.top会把请求转发到blog.toshout.top

依此配置,使不同域名绑定nginx服务器ip,并创建子配置文件即可。

https配置

由于本人使用的是阿里云服务器,CA证书也是在阿里云购买的免费证书。

1、下载证书

2、上传证书至/usr/local/nginx/cert目录

3、新建配置文件toshout.top_ssl.conf

 1 server {
 2     listen       443;
 3     server_name  toshout.top;
 4     ssl          on;
 5 
 6     ssl_certificate      /usr/local/nginx/cert/weixin.daq.pem;
 7     ssl_certificate_key  /usr/local/nginx/cert/weixin.daq.key;
 8 
 9     location / {
10         proxy_pass http://blog.toshout.top;
11         proxy_http_version 1.1;
12         proxy_set_header Host $host;
13         proxy_set_header X-Real-IP $remote_addr;
14         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
15         proxy_set_header Via "nginx";
16     }
17 }

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:javase 基本运算符和三大流程

下一篇:Java面向对象-------多态总结