标签 nginx 下的文章

server {
    server_name  www.example.com;
    listen 80;
    index index.php;
    root /var/www/blog;

    location / {
    try_files $uri $uri/ /index.php?$query_string;
  }

  location ~ \.php$ {
    #include snippets/fastcgi-php.conf;

    # Nginx php-fpm sock config:
    fastcgi_pass  unix:/run/php/php8.1-fpm.sock;
    #fastcgi_pass  127.0.0.1:9001;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }
}

获取到crt和key文件

mkdir /etc/nginx/cert
cp ssl.crt /etc/nginx/cert/ssl.crt
cp ssl.key /etc/nginx/cert/ssl.key

配置nginx

server {
        listen 443 ssl;
        server_name somedomain.com;

        ssl_certificate  /etc/nginx/cert/ssl.crt;
        ssl_certificate_key /etc/nginx/cert/ssl.key;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers         HIGH:!aNULL:!MD5;

        #...
}

server {
    listen 80;
    server_name somedomain.com;
    # 跳转到https
    rewrite ^(.*)$  https://$host$1 permanent;
}

重启nginx

nginx -t
nginx -s reload

server{
    server_name domain;
    root /var/www/html;
    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header host $host;
        proxy_set_header X-real-ip $remote_addr;
        proxy_set_header X-forward-for $proxy_add_x_forwarded_for;
    }
}

server {
  listen 80;
  server_name luntan;
  root /var/www/html;
  index index.php index.html;

  location / {
    try_files $uri $uri/ /index.php?$query_string;
  }

  location ~ \.php$ {
    fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }

  location ~ /\.ht {
    deny all;
  }
}