Symfony2,Wordpress和Nginx:配置文件应该如何

时间:2015-04-08 17:59:22

标签: wordpress symfony nginx

我在一个运行在Symfony2上的Nginx上设置了一个项目,其中包含Wordpress博客。 Wordpress博客在Web / Symfony2中。博客上的一些内容并不起作用(例如wp-admin上的无限302和一些CSS问题)。有人可以告诉我这个设置的正确配置文件应该是什么样子? 我看起来像这样:

server {
  listen 80;

  server_name project.com *.project.com;
  return 301 https://www.project.com$request_uri;
  root /usr/share/nginx/html/project.com/web;

  error_log /var/log/nginx/project.error.log;
  access_log /var/log/nginx/project.access.log;

  client_max_body_size 12M;

  # strip app.php/ prefix if it is present
  #rewrite ^/app\.php/?(.*)$ /$1 permanent;

  location / {
    index app.php;
    try_files $uri @rewriteapp;
    if ($http_host ~ "^[^.]+\.[^.]+$"){
        rewrite ^(.*)$ https:%1://www.$http_host$request_uri redirect;
    }
  }

  location @rewriteapp {
    rewrite ^(.*)$ /app.php/$1 last;
  }

  # 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:/var/run/php5-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param  HTTPS              off;
  }
}

server {
    listen 443;

    ssl on;
    ssl_certificate /etc/nginx/ssl/www.project.com/project-bundle.crt;
    ssl_certificate_key /etc/nginx/ssl/www.project.com/project.key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !MEDIUM";
    ssl_dhparam dh4096.pem;

    server_name project.com *.project.com;
    root /usr/share/nginx/html/project.com/web;

    error_log /var/log/nginx/project.error.log;
    access_log /var/log/nginx/project.access.log;

    client_max_body_size 12M;

    # strip app.php/ prefix if it is present
    rewrite ^/app\.php/?(.*)$ /$1 permanent;

    location / {
      index app.php;
      try_files $uri @rewriteapp;
      if ($http_host ~ "^[^.]+\.[^.]+$"){
          rewrite ^(.*)$ https:%1://www.$http_host$request_uri redirect;
      }
    }

    location /blog/wp-admin/ {
      index index.php;
    #  #try_files $uri @rewriteindex;
    #  try_files $uri $uri/ /index.php?$args;
    }

    #location @rewriteindex {
    #  rewrite ^(.*)$ /blog/wp-admin/index.php/$1 last;
    #}

    location @rewriteapp {
      rewrite ^(.*)$ /app.php/$1 last;
    }

    # 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:/var/run/php5-fpm.sock;
      fastcgi_split_path_info ^(.+\.php)(/.*)$;
      include fastcgi_params;
      fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
      fastcgi_param  HTTPS              off;
    }

    location .(js|jpg|png|css)$ {
        root /usr/share/nginx/html/project.com/web;
        expires 30d;
    }
}

这个配置文件只是一团糟。从头开始可能更好,但我不确定如何处理web / blog /中的Wordpress部分

1 个答案:

答案 0 :(得分:0)

location~ / blog {                 proxy_pass http://your_wp_server_url;                 proxy_set_header X-Real-IP $ remote_addr;                 proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;         } 并在nginx中为新站点启用的文件中定义了wordpress的服务器:

server{
 server_name your_wp_server_url;
 root path_to_wordpress;
 .
 . 
 .

}