Docker nginx和php分离配置

server {
  listen 80;
  server_name test.akiraka.net;
  index index.html index.htm index.php;
  root $webroot;
  set $webroot '/data/wwwroot/test.akiraka.net';
  access_log /data/wwwlogs/test.akiraka.net_nginx.log combined;

  include /usr/local/nginx/conf/rewrite/wordpress.conf;

  location ~ [^/]\.php(/|$) {
    # oneinstack有fastcgi.conf,不是请屏蔽
    include fastcgi.conf;
    include fastcgi_params;
    fastcgi_index index.php;
    fastcgi_pass php:9000;
    #fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_param SCRIPT_FILENAME $webroot$fastcgi_script_name;
  }
  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
    expires 30d;
    access_log off;
  }
  location ~ .*\.(js|css)?$ {
    expires 7d;
    access_log off;
  }
  location ~ /\.ht {
    deny all;
  }
}

如果Docker nginx和php做分离,nginx做配置必须要指定php的项目路径,而不是指定nginx下的项目路径,不然会找不到文件。也就是说nginx只是处理请求,php负责解析请求返回结果给nginx,那么项目文件就应该在php容器下。

server {
  listen 443 ssl http2;
  ssl_certificate /usr/local/nginx/conf/ssl/cloud.akiraka.net.pem;
  ssl_certificate_key /usr/local/nginx/conf/ssl/cloud.akiraka.net.key;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
  ssl_prefer_server_ciphers on;
  ssl_session_timeout 10m;
  ssl_session_cache builtin:1000 shared:SSL:10m;
  ssl_buffer_size 1400;
  add_header Strict-Transport-Security max-age=15768000;
  ssl_stapling on;
  ssl_stapling_verify on;
  root $webroot;
  set $webroot '/data/wwwroot/cloud.akiraka.net';
  server_name cloud.akiraka.net;
  access_log /data/wwwlogs/test.akiraka.net_nginx.log combined;
  if ($ssl_protocol = "") { return 301 https://$host$request_uri; }

  #include /usr/local/nginx/conf/rewrite/wordpress.conf;

  location ~ [^/]\.php(/|$) {
    # oneinstack有fastcgi.conf,不是请屏蔽
    include fastcgi.conf;
    include fastcgi_params;
    fastcgi_index index.php;
    fastcgi_pass php:9000;
    #fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_param SCRIPT_FILENAME $webroot$fastcgi_script_name;
  }
  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
    expires 30d;
    access_log off;
  }
  location ~ .*\.(js|css)?$ {
    expires 7d;
    access_log off;
  }
  location ~ /\.ht {
    deny all;
  }
}

版权声明:
作者:Akiraka
链接:https://www.akiraka.net/linux/nginx/133.html
来源:Akiraka
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
海报
Docker nginx和php分离配置
server { listen 80; server_name test.akiraka.net; index index.html index.htm index.php; root $webroot; set $webroot '/data/wwwroot/te……
<<上一篇
下一篇>>
文章目录
关闭
目 录