一个域名解析不同访问方法

  例如,域名名称是:ljjpm.com

  我想通过两种方式可以访问到同一个项目,例如:

  blog.ljjpm.com

  ljjpm.com

 

  实现过程:

  找到域名位置,解析两种不同的域名形式:

  一个域名解析不同访问方法_第1张图片

 

  找到nginx的配置文件

  仓鼠的位置是:etc/nginx/config.d

  新建配置域名文件:

  一个域名解析不同访问方法_第2张图片

 

  进行配置:

  (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

转载于:https://www.cnblogs.com/finalanddistance/p/10531335.html

你可能感兴趣的:(php,运维)