在localhost mac os x

时间:2016-01-18 03:29:32

标签: macos caching localhost assetic symfony

我的symfony 3项目发生了一个非常奇怪的错误。在做了一些研究之后,我将错误缩小到与系统范围的缓存有关。

为什么它不与symfony相关......

我将解释原因,但在您认为其他与symfony或资产缓存问题有关的事情之前,请阅读以下内容:

我每次部署时都运行以下shell脚本,以确保生产和开发环境的一切都干净。

chown -R distribution:distribution .
rm -rf var/cache/dev/*
rm -rf var/cache/prod/*
rm -rf web/css/*
rm -rf web/js/*
bin/console cache:clear --env=dev
bin/console cache:clear --env=prod --no-debug
bin/console assets:install web --symlink
bin/console assetic:dump --env=dev
bin/console assetic:dump --env=prod --no-debug
bin/console doctrine:schema:update --force --dump-sql
bin/console doctrine:schema:update --force --dump-sql --env=prod
chown -R distribution:distribution .
bin/console server:run

我通过SSH隧道访问计算机上的localhost来测试开发环境。

sudo ssh -L 3306:127.0.0.1:3306 -L 80:127.0.0.1:80 -L 8000:127.0.0.1:8000 -p 25000 fake_super_user_name@(server ip address here)

我可以随时访问我的浏览器并键入localhost:8000

随时访问的symfony开发版本

所有工作都在进行,直到我做了一些关于添加捆绑包并更改路径和文件名称以及位置等的重大更改...

为什么它的系统相关...

在谷歌浏览器中,当我转到我的页面并打开检查器时,我可以看到它试图访问已编译的文件-js_part_1_admin_1.js。这是我的javascript文件的旧版本。但是,当我进入服务器并查看我的FTP程序并通过web / js目录中的ls -al控制台时,该文件不存在!编译正确的文件-js_part_2_admin_1.js,但引用的文件绝不在我的服务器上。因此,它从我计算机上的某个地方抓取一个缓存的副本。

enter image description here

enter image description here

因此,请在浏览器中删除缓存...

这适用于我的生产网站的实际域名,但出于某种原因,当我尝试使用localhost删除缓存或完全从谷歌浏览器删除缓存时,似乎没有任何删除,并且它一直引用旧文件。我仍然可以通过在chrome中的url中键入about:cache来在缓存中看到此内容。如果您好奇我是如何尝试删除缓存的,我打开检查器并按住刷新按钮并选择“清空缓存并重新加载”。

enter image description here

好的,请使用其他浏览器......

我使用Firefox,Safari,甚至Opera以及所有这些,即使我从未使用过该浏览器,但在我通过localhost访问时仍然请求旧文件...

我猜测它存储在某种超级缓存中,因为它的localhost ......我不知道这是什么缓存在系统上以及如何删除它。

如果这里重要的是我的.htaccess文件在服务器上设置了文件的过期和缓存规则......我实际上是在尝试测试这个,所以我不想禁用它,但我和#39;我确定这是它缓存的原因,我只是想弄清楚如何清除localhost的缓存,这样我就可以再次开发,因为我知道我找到了合适的资产。

的.htaccess

# Use the front controller as index file. It serves as a fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex app.php

# By default, Apache does not evaluate symbolic links if you did not enable this
# feature in your server configuration. Uncomment the following line if you
# install assets as symlinks or if you experience problems related to symlinks
# when compiling LESS/Sass/CoffeScript assets.
Options FollowSymlinks

# Disabling MultiViews prevents unwanted negotiation, e.g. "/app" should not resolve
# to the front controller "/app.php" but be rewritten to "/app.php/app".
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Determine the RewriteBase automatically and set it as environment variable.
    # If you are using Apache aliases to do mass virtual hosting or installed the
    # project in a subdirectory, the base path will be prepended to allow proper
    # resolution of the app.php file and to redirect to the correct URI. It will
    # work in environments without path prefix as well, providing a safe, one-size
    # fits all solution. But as you do not need it in this case, you can comment
    # the following 2 lines to eliminate the overhead.
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]

    # Sets the HTTP_AUTHORIZATION header removed by Apache
    RewriteCond %{HTTP:Authorization} .
    RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect to URI without front controller to prevent duplicate content
    # (with and without `/app.php`). Only do this redirect on the initial
    # rewrite by Apache and not on subsequent cycles. Otherwise we would get an
    # endless redirect loop (request -> rewrite to front controller ->
    # redirect -> request -> ...).
    # So in case you get a "too many redirects" error or you always get redirected
    # to the start page because your Apache does not expose the REDIRECT_STATUS
    # environment variable, you have 2 choices:
    # - disable this feature by commenting the following 2 lines or
    # - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
    #   following RewriteCond (best solution)
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^app\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]

    # If the requested filename exists, simply serve it.
    # We only want to let Apache serve files and not directories.
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]

    # Rewrite all other queries to the front controller.
    RewriteRule ^ %{ENV:BASE}/app.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        # When mod_rewrite is not available, we instruct a temporary redirect of
        # the start page to the front controller explicitly so that the website
        # and the generated links can still be used.
        RedirectMatch 302 ^/$ /app.php/
        # RedirectTemp cannot be used instead
    </IfModule>
</IfModule>

# These rules need to be at the bottom!
# Make it aware of True Type Fonts for Web Fonts.
AddType application/x-font-ttf .ttf

Header unset Pragma
FileETag None
Header unset ETag 

<IfModule mod_deflate.c>
  # Compress HTML, CSS, JavaScript, Text, XML and fonts
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml

  # Remove browser bugs (only needed for really old browsers)
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  Header append Vary User-Agent
</IfModule>

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/x-font-ttf "access plus 1 year"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType text/js "access 1 week"
ExpiresByType application/javascript "access 1 week"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
## EXPIRES CACHING ##

短版

如果我错过了解决此问题所需的任何信息,请告诉我,我会立即发布。简短的故事,我的本地系统不知何故存储了我无法删除的缓存。如何在所有浏览器中删除特定于localhost的此缓存?

1 个答案:

答案 0 :(得分:0)

好的,我找到了解决方案...但只是一点点。 Assetic给出了一个真正的错误,修复错误使缓存开始修复它自己。

尽管如此,这种情况下的缓存行为非常奇怪。