当前位置:Gxlcms > PHP教程 > nginx对于https的配置

nginx对于https的配置

时间:2021-07-01 10:21:17 帮助过:14人阅读

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教程有兴趣的朋友有所帮助。

人气教程排行