服务器nginx配置,端口转发、https配置

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #map $http_upgrade $connection_upgrade {
    #    default upgrade;
    #    ''      close;
    #}

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;
    client_max_body_size 10m;
    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  www.hbtjkj.com.cn;
		server_name_in_redirect off;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        rewrite ^(.*)$ https://$host$1;
        location / {
           root   html;
           index  index.html index.html;
           try_files $uri $uri/ /index.html;
        }

       	location /crad/ {
           root   html;
           index  fenglei.html fenglei.htm;
           try_files $uri $uri/ /fenglei.html;
        }

		location /miniprogramimg/ {
           root   html;
           index  fenglei.html fenglei.htm;
           try_files $uri $uri/ /fenglei.html;
        }

		location /ywlxcxImg/ {
           root   html;
           index  fenglei.html fenglei.htm;
           try_files $uri $uri/ /fenglei.html;
        }

        location /api {
			#Proxy Settings
			add_header Access-Control-Allow-Origin $http_origin;
			add_header Access-Control-Allow-Headers *;
			add_header Access-Control-Allow-Methods *;
 
			proxy_redirect     off;
			proxy_set_header   Host             $host:$server_port;
			proxy_set_header   X-Real-IP        $remote_addr;
			proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
			proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
			proxy_max_temp_file_size 0;
			proxy_connect_timeout      90;
			proxy_send_timeout         90;
			proxy_read_timeout         90;			
			proxy_pass https://localhost:9096;
        }

        location /api/wx {
            #Proxy Settings
            add_header Access-Control-Allow-Origin $http_origin;
            add_header Access-Control-Allow-Headers *;
            add_header Access-Control-Allow-Methods *;
 
            proxy_redirect     off;
            proxy_http_version 1.1;
            proxy_set_header   Host             $host:$server_port;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme; 
            proxy_set_header   Upgrade $http_upgrade;
            proxy_set_header   Connection  "upgrade"; 
            proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
            proxy_max_temp_file_size 0;
            proxy_connect_timeout      90;
            proxy_send_timeout         90;
            proxy_read_timeout         90;          
            proxy_pass https://localhost:9096;

        }
        	
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
     #proxy_pass http://127.0.0.1:8080;
    #    }
    #}

    # HTTPS server
    #
    server {
		listen       443 ssl;
		server_name  hbtjkj.com.cn;
		server_name_in_redirect off;

		ssl_certificate      9447281_www.hbtjkj.com.cn.pem;
		ssl_certificate_key  9447281_www.hbtjkj.com.cn.key;

		ssl_session_cache    shared:SSL:1m;
		ssl_session_timeout  5m;
		ssl_ciphers  HIGH:!aNULL:!MD5;
		ssl_prefer_server_ciphers  on;
		 ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
		location / {
			root   html;
			index  index.html index.htm;
		}

        location /api {
			#Proxy Settings
            add_header Access-Control-Allow-Origin $http_origin;
            add_header Access-Control-Allow-Headers *;
            add_header Access-Control-Allow-Methods *;
 
            proxy_redirect     off;
            proxy_http_version 1.1;
            proxy_set_header   Host             $host:$server_port;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_set_header   Upgrade $http_upgrade;
            proxy_set_header   Connection  "upgrade"; 
            proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
            proxy_max_temp_file_size 0;
            proxy_connect_timeout      90;
            proxy_send_timeout         90;
            proxy_read_timeout         90;          
            proxy_pass https://localhost:9096;
        }

        location /api/wx {
            #Proxy Settings
            add_header Access-Control-Allow-Origin $http_origin;
            add_header Access-Control-Allow-Headers *;
            add_header Access-Control-Allow-Methods *;
 
            proxy_redirect     off;
            proxy_http_version 1.1;
            proxy_set_header   Host             $host:$server_port;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme; 
            proxy_set_header   Upgrade $http_upgrade;
            proxy_set_header   Connection  "upgrade"; 
            proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
            proxy_max_temp_file_size 0;
            proxy_connect_timeout      90;
            proxy_send_timeout         90;
            proxy_read_timeout         90;          
            proxy_pass https://localhost:9096;
        }
    }
}

posted @ 2023-06-15 17:57  lambertlt  阅读(423)  评论(0编辑  收藏  举报