在NGINX FastCGI Linux上解析HTML文件中的PHP时遇到问题

时间:2018-08-10 18:01:29

标签: php html nginx fastcgi

我正在尝试将我的网站从LAMP迁移到AWS on Linux上的NGINX FastCGI,并且在解析网站中某些旧版.htm文件中的PHP时遇到问题。

我已经尝试过这里列出的解决方案:

具体地说,我正在使用:

location ~ \.(php|html|htm)$ {

security.limit_extensions = .php .htm .html

在我的/etc/nginx/sites-available/mybrokensite.com和/etc/php-fpm.d/www.conf文件中。

当我在浏览器中打开.htm文件时,我只会得到一个空白页。当我查看源代码时,我在文件中看到了整个原始php和html。如果我以.php扩展名重命名该文件,则它将解释php,并得到在浏览器中期望的格式化html文件。

我使用以下步骤来设置NGINX FastCGI Wordpress服务器:

https://gist.github.com/ericandrewlewis/95239573dc97c0e86714

这是我的配置:

# Define the microcache path.
fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=microcache:100m inactive=60m;

# Redirect http traffic to https
server {
  listen [::]:80;
  listen 80;

  server_name www.mybrokensite.com mybrokensite.com;

  return 301 https://mybrokensite.com$request_uri;
}

# Redirect www https traffic to non-www https
server {
  listen 443 ssl;

  ssl_certificate_key /etc/sslmate/mybrokensite.com.key;
  ssl_certificate /etc/sslmate/mybrokensite.com.chained.crt;

  server_name www.mybrokensite.com;

  return 301 https://mybrokensite.com$request_uri;
}

server {
  listen 443 ssl;

  server_name mybrokensite.com;

  # Include defaults for allowed SSL/TLS protocols and handshake caches.
  include h5bp/directive-only/ssl.conf;

  # config to enable HSTS(HTTP Strict Transport Security) https://developer.mozilla.org/en-US/docs/Security/HTTP_Strict_Transport_Security
  # to avoid ssl stripping https://en.wikipedia.org/wiki/SSL_stripping#SSL_stripping
  add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";

  ssl_certificate_key /etc/sslmate/mybrokensite.com.key;
  ssl_certificate /etc/sslmate/mybrokensite.com.chained.crt;

  # Path for static files
  root /sites/mybrokensite.com/public;

  #Specify a charset
  charset utf-8;

  # Include the basic h5bp config set
  include h5bp/basic.conf;

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

  location ~ \.(php|html|htm)$ {
    fastcgi_cache  microcache;
    fastcgi_cache_key $scheme$host$request_method$request_uri;
    fastcgi_cache_valid 200 304 10m;
    fastcgi_cache_use_stale updating;
    fastcgi_max_temp_file_size 1M;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
    include        fastcgi_params;


    # Local variables to track whether to serve a microcached page or not.
    set $no_cache_set 0;
    set $no_cache_get 0;

    # If a request comes in with a X-Nginx-Cache-Purge: 1 header, do not grab from cache
    # But note that we will still store to cache
    # We use this to proactively update items in the cache!
    if ( $http_x_nginx_cache_purge ) {
      set $no_cache_get 1;
    }

    # If the user has a user logged-in cookie, circumvent the microcache.
    if ( $http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) {
      set $no_cache_set 1;
      set $no_cache_get 1;
    }

    # fastcgi_no_cache means "Do not store this proxy response in the cache"
    fastcgi_no_cache $no_cache_set;
    # fastcgi_cache_bypass means "Do not look in the cache for this request"
    fastcgi_cache_bypass $no_cache_get;
  }
}

我的网站主要是一个Wordpress网站,其中包含一些旧的.htm文件,其中包含php。我是NGINX的新手,我们将不胜感激。

0 个答案:

没有答案