一個域名解析不一樣訪問方法

  例如,域名名稱是:ljjpm.comphp

  我想經過兩種方式能夠訪問到同一個項目,例如:html

  blog.ljjpm.comnginx

  ljjpm.comsession

 

  實現過程:spa

  找到域名位置,解析兩種不一樣的域名形式:3d

  

 

  找到nginx的配置文件code

  倉鼠的位置是:etc/nginx/config.dserver

  新建配置域名文件:htm

  

 

  進行配置:blog

  (1)www.ljjpm.com.config

  

server {
    # 端口號
    listen 443;
    # 綁定域名
    server_name www.ljjpm.com;

    ssl on;
    # 你須要綁定到哪一個文件夾
    root /var/www/blog;

    index index.html index.php;

    ssl_certificate   cert/1849646_www.ljjpm.com.pem;

    ssl_certificate_key  cert/1849646_www.ljjpm.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配置(爲了nginx可以讀取php代碼)
    location ~ \.php {
 
            fastcgi_pass 127.0.0.1:9000;
 
           fastcgi_index index.php;

            client_max_body_size 22m;

            # 這兩句也是用於開啓路由規則僞靜態
            fastcgi_split_path_info ^(.+\.php)(.*)$;
           fastcgi_param PATH_INFO $fastcgi_path_info;
 
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 
            include    fastcgi_params;
 
        }

     # 500 404的錯誤文件
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
             root   /usr/share/nginx/html;
        }
}

server {
    server_name  ljjpm.com;
    rewrite ^(.*)$ https://www.ljjpm.com$1 permanent;
}

server {
    # 端口號
    listen       80;
    # 綁定域名
    server_name  www.ljjpm.com;
    # 你須要綁定到哪一個文件夾
    root   /var/www/blog/;
    # 重定向到443端口,這樣就能夠不輸入https也能訪問
    rewrite ^(.*)$ https://${server_name}$1 permanent; 

    location / {
        # 默認加載文件
        index  index.html index.php;
        # 開啓路由規則僞靜態
        if (!-e $request_filename) {
            rewrite  ^(.*)$  /index.php?s=/$1  last;
            break;
        }
    }

    # 500 404的錯誤文件
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }


    location ~ \.php {
 
        fastcgi_pass 127.0.0.1:9000;
 
        fastcgi_index index.php;

        client_max_body_size 22m;

        # 這兩句也是用於開啓路由規則僞靜態
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
 
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 
        include    fastcgi_params;
 
    }

}

 

  (2)blog.ljjpm.com

server {
    # 端口號
    listen       80;
    # 綁定域名
    server_name  blog.ljjpm.com;
    # 你須要綁定到哪一個文件夾
    root   /var/www/blog/; 

    location / {
        # 默認加載文件
        index  index.html index.php;
        # 開啓路由規則僞靜態
        if (!-e $request_filename) {
            rewrite  ^(.*)$  /index.php?s=/$1  last;
            break;
        }
    }

    # 500 404的錯誤文件
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }


    location ~ \.php {
 
        fastcgi_pass 127.0.0.1:9000;
 
        fastcgi_index index.php;

        client_max_body_size 22m;

        # 這兩句也是用於開啓路由規則僞靜態
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
 
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 
        include    fastcgi_params;
 
    }

}

 

  從上面咱們能夠看出,ssl證書的配置,咱們只須要在一個配置文件中配置就能夠啦

 

  以上

  END

相關文章
相關標籤/搜索