【问题标题】:Symfony2, Wordpress and Nginx: How should configuration file look likeSymfony2、Wordpress 和 Nginx:配置文件应该是什么样子
【发布时间】:2015-12-11 08:29:31
【问题描述】:

我在 Symfony2 上运行的 Nginx 上设置了一个项目,其中包含 Wordpress 博客。 Wordpress 博客位于 Symfony2 中的 web/ 内部。博客上的某些内容不起作用(例如 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 部分

【问题讨论】:

    标签: wordpress symfony nginx


    【解决方案1】:

    位置 ~ /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;
     .
     . 
     .
    
    }
    

    【讨论】:

    • 我现在无法测试它,但它适用于像 example.com/blog 这样的博客网址吗?
    猜你喜欢
    • 1970-01-01
    • 2013-09-02
    • 2014-04-10
    • 2013-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-12
    • 1970-01-01
    相关资源
    最近更新 更多