我配置如下,我开启了http转发到https,且开启了https功能,ssl证书是阿里免费申请的 

#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;

    #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;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen     80;
        server_name  localhost;
		rewrite ^ https://$host$request_uri? permanent;
		return 301 https//www.tsdsyy.com.cn$request_uri; 
			
    	
    	
        #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;
    #    }
    #}


    # HTTPS server
    
    server {
        listen       443 ssl;
        server_name  www.tsdsyy.com.cn;
		
        ssl_certificate      cert\\ssl.pem;
        ssl_certificate_key  cert\\ssl.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

          location / {
            root  "C:/Users/Administrator/Desktop/page";
            index  index.html;
        }

	 
        location /api/{
       		proxy_connect_timeout  1800s;#nginx跟后端服务器连接超时时间(代理连接超时)
		proxy_send_timeout  1800s;#后端服务器数据回传时间(代理发送超时)
		proxy_read_timeout  1800s;#连接成功后,后端服务器响应时间(代理接收超时)
		proxy_set_header Host $host:$server_port;
		proxy_set_header Cookie $http_cookie;
	        proxy_set_header X-Forwarded-Host $host;
	        proxy_set_header X-Forwarded-Server $host;
	        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	        proxy_set_header X-real-ip $remote_addr;
	        proxy_pass http://127.0.0.1:8080/api/;  #注意:使用代理地址时末尾记得加上斜杠"/"。  





allow 27.224.0.0/16;
allow 27.226.0.0/16;
allow 42.88.0.0/16;
allow 42.89.0.0/16;
allow 42.92.0.0/16;
allow 42.94.0.0/16;
allow 42.95.0.0/16;
allow 59.76.0.0/16;
allow 60.13.0.0/16;
allow 60.164.0.0/16;
allow 60.165.0.0/16;
allow 61.134.0.0/16;
allow 61.178.0.0/16;
allow 61.234.0.0/16;
allow 110.220.0.0/16;
allow 111.11.0.0/16;
allow 111.115.0.0/16;
allow 115.85.0.0/16;
allow 117.156.0.0/16;
allow 117.157.0.0/16;
allow 118.180.0.0/16;
allow 118.182.0.0/16;
allow 118.183.0.0/16;
allow 123.81.0.0/16;
allow 124.152.0.0/16;
allow 125.74.0.0/16;
allow 125.75.0.0/16;
allow 125.76.0.0/16;
allow 180.95.0.0/16;
allow 210.26.0.0/16;
allow 218.203.0.0/16;
allow 221.7.0.0/16;
allow 222.57.0.0/16;
deny all;

			
    	}
    	
    }

}

 

在重启多次发现配置不生效,一直是nginx默认欢迎页

问题原因

nginx使用双击开启或者非正常关闭,nginx进程在后台有缓存

解决办法

在进程中杀掉所有nginx进程,使用命令nginx再次启动。