发布于: 2022-05-28 14:02:08

Nginx


# 解决跨域  在域名站点 / 目录下添加
add_header Access-Control-Allow-Origin *;

#服务器域名跳转
server{
   listen 80;
   server_name xxx.com;
   rewrite ^(.*)$ https://www.${server_name}$1 permanent;
}
#服务器域名跳转
server{
   listen 80;
   server_name www.xxx.com;
   rewrite ^(.*)$ https://${server_name}$1 permanent;
}
#服务器域名跳转
server {
   listen 443;
   ssl on;
   server_name xxx.com;
   rewrite ^(.*)$ https://www.${server_name}$1 permanent;
   ssl_certificate   /etc/nginx/cert/xxxxxxx.pem;
   ssl_certificate_key  /etc/nginx/cert/xxxxxxx.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;
}
#443配置
server {
       listen 443;
       server_name www.xxx.com;
       ssl on;
       # SSL configuration
       # listen 443 ssl default_server;
       # listen [::]:443 ssl default_server;
       # include snippets/snakeoil.conf;

       root /xxxx/public;

       # Add index.php to the list if you are using PHP
       index index.php index.htm index.html;

       ssl_certificate   /etc/nginx/cert/xxxxxxx.pem;
       ssl_certificate_key  /etc/nginx/cert/xxxxxx.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 / {
              try_files $uri $uri/ /index.php?$query_string;
       }

       # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
       location ~ \.php$ {
               #fastcgi_pass 127.0.0.1:9000;
               fastcgi_pass unix:/run/php/php7.2-fpm.sock; #这个unix管道速度要比端口速度快,具体内容去看nginx配置文档
       }
}


server {
   listen   80;
   server_name yumin.com www.yumin.com;
   location / {
       if (!-e $request_filename){
           rewrite (.*) /index.php; #所有页面访问index.php
       }
   }
   location ^~ /protected
   {
       deny all;
   }
 
 
   if ($host ~* www.oldyuming.com) {
       rewrite ^/(.*)$ http://www.newyumin.com/$1 permanent;
   }

   set $subdomain '';
   if ( $host ~* (\b(?!www\b).+)\.yumin.com ){
     set $subdomain $1;
   }
   index index.html index.htm index.php;

   root /mnt/www/$subdomain;
   
   location ~ .*\.(js|css)?$
   {
       expires 1h;
   }
   location ~ ^(.*)\/\.svn\/
   {
       return 404;
   }
}



延伸阅读
    发表评论