Nginx服务器配置 , ssl配置

本文详细介绍了Nginx服务器的配置方法,包括基本设置、错误日志管理、连接参数调整、压缩策略、静态资源缓存及防盗链设置等。特别关注了HTTPS配置,涵盖SSL证书绑定、加密套件选择、协议版本设定等关键步骤,适用于网站安全性和性能优化。

Nginx服务器配置 , ssl配置



user nginx nginx;
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;
    server_tokens off;
    #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;
    # 指定连接到后端Fastcgi的超时时间(单位:秒)
    fastcgi_connect_timeout 300;
    # 向Fastcgi传送请求的超时时间,这个值是指已经完成两次握手后向Fastcgi传送请求的超时时间(单位:秒)
    fastcgi_send_timeout 300;
    # 指定接收Fastcgi应答的超时时间,这个值是指已经完成两次握手后接收Fastcgi应答超时时间(单位:秒)
    fastcgi_read_timeout 300;	

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;
    
    # 设置将被gzip压缩的响应的最小长度
     gzip_min_length 200;
    # # 压缩级别 1-9
     gzip_comp_level 6;
    # # 压缩在缓冲区块数和每块大小
     gzip_buffers 32 4k;   # | 16 8k;
    # # 设置压缩响应所需的最低HTTP请求版本
     gzip_http_version 1.0;
     gzip_types      text/plain  text/css text/xml application/xml application/json application/javascript;    

#laravel 框架配置
    server {
        listen       80;
        server_name  你的域名;
        root /var/www/html/你的项目路径;

        #charset koi8-r;

       # access_log  /usr/local/nginx/logs/success.log  main;

        location / {
          #if (!-e $request_filename) {
          #        rewrite ^(.*)$ /index.php/$1  last;
          #        break;
          #}
            try_files $uri $uri/ /index.php?$query_string;
			rewrite ^(.*) https://$host$1 permanent;
            index  index.php;
        }
        #支持php
		location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            # 非必须 默认索引页
            #fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include         fastcgi_params;
        }
        #防攻击
        location ~ /thinkphp {
               rewrite ^ https:www.baidu.com/ redirect;
               break;
        }
        #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;
        }
        # 缓存
        location ~* \.(jpg|jpeg|gif|bmp|png|ico|svg|mp4|mp3){
             expires 7d; # 缓存1天
        }
        location ~* \.(css|js){
             expires 1d; # 缓存1天
        }
        #图片防盗链
        location ~* \.(jpg|jpeg|gif|bmp|png|ico|svg|mp4|mp3)$ {
             valid_referers none blocked *.1314000.cn 1314000.cn;
             if ($invalid_referer) {
                 return 403;
              }
        }
        
	
	
	#ThinkPHP框架配置
	
	server {
        listen       80;
        server_name  shop.jokenzhang.xyz;
        root /var/www/html/pinyg/public;

        #access_log  /usr/local/ngin/logs/success_php1314000cn.log  main;

        location / {
                #if (!-e $request_filename) {
                #       rewrite  ^(.*)$  /index.php?s=/$1  last;
                #       break;
                #}
		        rewrite ^(.*) https://$host$1 permanent;
                index  index.html index.htm index.php;
        }
        # 防攻击
        location ~ /thinkphp {
                rewrite ^ https://www.baidu.com/ redirect;
                break;
        }
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include         fastcgi_params;
        }
	}

    
	#品优购商城项目后台管理系统
	
	server {
        listen       80;
        server_name  adminshop.jokenzhang.xyz;
        root /var/www/html/pinyg/public;

        #charset koi8-r;

       # access_log  /usr/local/nginx/logs/success.log  main;

        location / {
          #  if (!-e $request_filename) {
           #         rewrite ^(.*)$ /index.php/$1  last;
            #        break;
           #}
            try_files $uri $uri/ /index.php?$query_string;
            
            index  index.php;
        }
        #支持php
		location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            # 非必须 默认索引页
            #fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include         fastcgi_params;
        }
        #防攻击
        location ~ /thinkphp {
               rewrite ^ https:www.baidu.com/ redirect;
               break;
        }
        #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;
        }
        # 缓存
        location ~* \.(jpg|jpeg|gif|bmp|png|ico|svg|mp4|mp3){
             expires 7d; # 缓存1天
        }
        location ~* \.(css|js){
             expires 1d; # 缓存1天
        }
        #图片防盗链
        location ~* \.(jpg|jpeg|gif|bmp|png|ico|svg|mp4|mp3)$ {
             valid_referers none blocked *.1314000.cn 1314000.cn;
             if ($invalid_referer) {
                 return 403;
              }
        }

    # HTTPS server
    #
	
	##商城项目的 https配置##
	
	# 以下属性中以ssl开头的属性代表与证书配置有关,其他属性请根据自己的需要进行配置。
	server {
		listen 443 ssl;
		server_name  www.baidu.com;  # www.baidu.com修改为您证书绑定的域名。
		#ssl on;   #设置为on启用SSL功能。
		root 你的项目目录绝对路径;
		index index.php;#默认主页
		ssl_certificate name.pem;   #将domain name.pem替换成您证书的文件名。
		ssl_certificate_key cert/name.key;   #将domain name.key替换成您证书的密钥文件名。
		ssl_session_timeout 5m;
		ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;  #使用此加密套件。
		ssl_protocols TLSv1 TLSv1.1 TLSv1.2;   #使用该协议进行配置。
		ssl_prefer_server_ciphers on;   
		location / {
                if (!-e $request_filename) {
                       rewrite  ^(.*)$  /index.php?s=/$1  last;
                       break;
                }
                index  index.html index.htm index.php;
        }
        # 防攻击
        location ~ /thinkphp {
                rewrite ^ https://www.baidu.com/ redirect;
                break;
        }
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include         fastcgi_params;
        }
	}

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值