beego項目部署到nginx(含http轉https)

beego項目部署到nginx(含http轉https)

   以前的程序部署到服務器採用的直接部署,比較方便,如今把它部署到nginx,以便後續的反向代理和負載均衡,同時,由於要接入微信小程序,因此須要將以前的域名http://www.xxxxxx.com轉成https://www.xxxxxx.com。
更多內容可關注公衆號,裏面都是做者原創。

1,安裝Nginx。       javascript

   卸載原來的nginx:sudo apt-get —purge autoremove nginxphp

    安裝nginx:sudo apt-get install nginxcss

    如圖:java

   

 

2,部署beego到nginx,增長ssl證書(證書的申請能夠到騰訊雲註冊帳號申請,如今有免費一年的證書使用)。node

修改/etc/nginx/nginx.conf。也能夠在/etc/nginx/conf.d/目錄下新增conf文件來配置專屬於某個服務。此處配置的是/etc/nginx/nginx.conf。nginx

user www-data;
worker_processes auto;
pid /run/nginx.pid;


events {
  worker_connections 768;
  # multi_accept on;
}


http {


  ##
  # Basic Settings
  ##


  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  types_hash_max_size 2048;
  # server_tokens off;


  # server_names_hash_bucket_size 64;
  # server_name_in_redirect off;


  include /etc/nginx/mime.types;
  default_type application/octet-stream;


  ##
  # SSL Settings
  ##


  ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
  ssl_prefer_server_ciphers on;


  ##
  # Logging Settings
  ##


  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;


  ##
  # Gzip Settings
  ##


  gzip on;
  gzip_disable "msie6";


  # gzip_vary on;
  # gzip_proxied any;
  # gzip_comp_level 6;
  # gzip_buffers 16 8k;
  # gzip_http_version 1.1;
  # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;


  ##
  # Virtual Host Configs
  ##


  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;


  server {
           listen       80;
          server_name  www.XXXXXX.com; #你的域名


          # 配置https
          ssl          on;
          ssl_certificate 1_XXXXXX.com_bundle.crt;   #你申請的nginx中的ssl證書
          ssl_certificate_key 2_XXXXXX.com.key;     #你申請的nginx中的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;




        charset utf-8;
        access_log  /home/ubuntu/beego/access.log; #該目錄建議是你的部署文件目錄


        location /(css|js|fonts|img)/ {
            access_log off;
            expires 1d;


            root "/home/ubuntu/beego/static";#該文件是你beego項目中的static靜態文件路徑
          try_files $uri @backend;
        }


        location / {
            try_files /_not_exists_ @backend;
        }


        location @backend {
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header Host            $http_host;


            proxy_pass http://127.0.0.1:8999;  #代理指向的beego項目地址
        }
  }
}




#mail {
#  # See sample authentication script at:
#  # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#  # auth_http localhost/auth.php;
#  # pop3_capabilities "TOP" "USER";
#  # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#  server {
#    listen     localhost:110;
#    protocol   pop3;
#    proxy      on;
#  }
# 
#  server {
#    listen     localhost:143;
#    protocol   imap;
#    proxy      on;
#  }
#}
3,加載nginx配置,啓動nginx服務
        加載配置:sudo nginx -s reload
        啓動nginx:sudo service nginx restart
4,啓動beego服務。驗證。
       
        此時已經將80代理到beego項目的8999端口。
相關文章
相關標籤/搜索