Rumah  >  Artikel  >  pembangunan bahagian belakang  >  nginx对于https的配置

nginx对于https的配置

WBOY
WBOYasal
2016-08-08 09:29:171088semak imbas
server {
	listen       443;
	server_name www.roamwifi.net;
	#配置发布目录为/usr/local/nginx/data/rw-ows
	root  /usr/local/nginx/data/rw-ows;
        ssl                  on; 
        ssl_certificate      server.pem; 
        ssl_certificate_key  server.key; 
        ssl_session_timeout  5m; 
        ssl_protocols  SSLv3 TLSv1; 
        ssl_ciphers  HIGH:!ADH:!EXPORT56:RC4+RSA:+MEDIUM; 
        ssl_prefer_server_ciphers   on;
	#添加以下405代码
	error_page 405 =200 $uri; 
	location / {
		proxy_next_upstream http_502 http_504 error timeout invalid_header;
		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_pass http://rw-ows;
               
                 #=========================CORS nginx配置=============================
               if ($http_origin ~* (https?://[^/]*\.roamwifi\.net(:[0-9]+)?)$) {
                 set $cors "true";
                }
               if ($request_method = 'OPTIONS') {
                     set $cors "${cors}options";  
                 }
                if ($request_method = 'GET') {
                   set $cors "${cors}get";  
                }
                if ($request_method = 'POST') {
                   set $cors "${cors}post";
                }
                if ($cors = "trueget") {
                  add_header 'Access-Control-Allow-Origin' "$http_origin";
                  add_header 'Access-Control-Allow-Credentials' 'true';
                }
                if ($cors = "truepost") {
                 add_header 'Access-Control-Allow-Origin' "$http_origin";
                 add_header 'Access-Control-Allow-Credentials' 'true';
                 }
                if ($cors = "trueoptions") {
       		# add_header 'Access-Control-Allow-Origin' "$http_origin";
                  add_header 'Access-Control-Allow-Origin' '*';  
       		 add_header 'Access-Control-Allow-Credentials' 'true';
       		 add_header 'Access-Control-Max-Age' 1728000;
       		 add_header 'Access-Control-Allow-Headers' 'Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since';
                 add_header 'Content-Length' 0;
                 add_header 'Content-Type' 'text/plain charset=UTF-8';
                # return 204;
                 return 200;
     		 }
	}
	  location ~ .*\.(jsp|do)?$ {
                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_pass http://rw-ows;
        }
        location ~ .*\.(html|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
                root /usr/local/nginx/data/rw-ows;
                expires      1d;
        }
}

以上就介绍了nginx对于https的配置,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn