Nginx + php + http / https 서버 설정

6499 단어 개발 환경 설정
테스트 시스템: ubantu 16.04 테스트 시간: 2017 - 12 - 21
SSL 인증서 설명
블 로 거들 이 사용 하 는 DV 무료 인증서 테스트
SSL Key 와 CSR 파일 또는 PEM 파일 에 대하 여
일반 SSL 배급 사 에서 키 나 csr 를 제공 합 니 다.없 으 면 스스로 생 성 할 수 있 고 OpenSSL 을 사용 합 니 다..key 비밀 키 입 니 다.
HTTPS 설정
먼저 nginx 호스트 설정 디 렉 터 리 에 들 어가 야 합 니 다: / var / nginx / sites - enabled * * 설정 https 와 http 는 두 가지 방식 이 있 습 니 다.
  • 하 나 는 둘 이 공존 하 는 것 이다
  • 다른 하 나 는 http 점프 강제로 https
  • 80 포트 와 443 포트 를 동시에 감청 합 니 다.
    server {
        listen              80;#    80 443  
        listen              443 ssl;
        server_name         example.com;
        root /var/www/html;
        index index.php index.html index.htm index.nginx-debian.html;
        #    
        ssl_certificate     example.com.crt;
        #    
        ssl_certificate_key example.com.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;
        #php  
        location ~ \.php$ {
                    include snippets/fastcgi-php.conf;
    
            #
            #       # With php7.0-cgi alone:
            #       fastcgi_pass 127.0.0.1:9000;
            #       # With php7.0-fpm:
                    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            }
    }

    강제 http 점프 https
    server {
            listen 80;
            server_name example.com;
            return 301 https://$server_name$request_uri;
    }
    server {
        listen 443 ssl;
        server_name example.com;
        ssl on;
        root /var/www/html;
        index index.php index.html index.htm index.nginx-debian.html;
        ssl_certificate   example.com.curl;
        ssl_certificate_key  example.com.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 / {
            root /var/www/html;
            index index.php index.html index.htm index.nginx-debian.html;
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
        }
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            location ~ \.php$ {
                    include snippets/fastcgi-php.conf;
    
            #
            #       # With php7.0-cgi alone:
            #       fastcgi_pass 127.0.0.1:9000;
            #       # With php7.0-fpm:
                    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            }
    
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            location ~ /\.ht {
                    deny all;
            }
            # deny .git access
            location ~ /\.git {
                deny all;
            }
    }

    참조: 주소 1

    좋은 웹페이지 즐겨찾기