Home  >  Article  >  Backend Development  >  nginx configuration for https

nginx configuration for https

WBOY
WBOYOriginal
2016-08-08 09:29:171091browse
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;
        }
}

The above introduces the configuration of nginx for https, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn