我有一个问题,从Apache迁移到Nginx的网站。 大多数的东西工作正常,我只是在这里有一些静态文件的一个非常具体的问题。
在服务器的文档中,安装了phpBB,主题中的.css文件通过PHP解释器传递,而不是直接由nginx传递,我只是想不出为什么。
我的nginx网站configuration:
server { listen 81; ## listen for ipv4 listen [::]:81 default ipv6only=on; ## listen for ipv6 server_name www.wanda.eu; access_log /var/log/nginx/wanda.eu.access.log; error_log /var/log/nginx/wanda.eu.error.log debug; root /srv/www/wanda.eu; location /static { try_files $uri $uri/ @php_index =404; expires 24h; } location / { #Secure arbitrary code execution on NON php files (ex: .png with PHP code) fastcgi_index index.php; try_files $uri $uri/ /index.php =404; include /etc/nginx/fastcgi_params; fastcgi_pass unix:/tmp/php-cgi/php-cgi.socket; fastcgi_param SCRIPT_FILENAME /srv/www/wanda.eu$fastcgi_script_name; } location /dynamic { #Secure arbitrary code execution on NON php files (ex: .png with PHP code) try_files $uri $uri/ /dynamic/index.php =404; include /etc/nginx/fastcgi_params; fastcgi_index index.php; fastcgi_pass unix:/tmp/php-cgi/php-cgi.socket; fastcgi_param SCRIPT_FILENAME /srv/www/wanda.eu$fastcgi_script_name; } }
(dynamic块是网站的一个特殊的块,在那里configuration,生成图像 – 工作正常)
这里的问题是请求url /forum/styles/bastisstyle/theme/stylesheet.css
在error_log中启用debuggingfunction后,我在那里看到以下内容:
2012/08/08 16:24:20 [debug] 13885#0: *669 http request line: "GET /forum/styles/bastisstyle/theme/stylesheet.css HTTP/1.1" 2012/08/08 16:24:20 [debug] 13885#0: *669 http uri: "/forum/styles/bastisstyle/theme/stylesheet.css" 2012/08/08 16:24:20 [debug] 13885#0: *669 http args: "" 2012/08/08 16:24:20 [debug] 13885#0: *669 http exten: "css" 2012/08/08 16:24:20 [debug] 13885#0: *669 http process request header line 2012/08/08 16:24:20 [debug] 13885#0: *669 http header: "Host: www.wanda.eu:81" 2012/08/08 16:24:20 [debug] 13885#0: *669 http header: "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1" 2012/08/08 16:24:20 [debug] 13885#0: *669 http header: "Accept: text/css,*/*;q=0.1" 2012/08/08 16:24:20 [debug] 13885#0: *669 http header: "Accept-Language: en-us,en;q=0.5" 2012/08/08 16:24:20 [debug] 13885#0: *669 http header: "Accept-Encoding: gzip, deflate" 2012/08/08 16:24:20 [debug] 13885#0: *669 http header: "Connection: keep-alive" 2012/08/08 16:24:20 [debug] 13885#0: *669 http header: "Referer: http://www.wanda.eu:81/forum/" 2012/08/08 16:24:20 [debug] 13885#0: *669 http alloc large header buffer 2012/08/08 16:24:20 [debug] 13885#0: *669 malloc: 0000000001469B00:256 2012/08/08 16:24:20 [debug] 13885#0: *669 malloc: 0000000001497800:8192 2012/08/08 16:24:20 [debug] 13885#0: *669 http large header alloc: 0000000001497800 8192 2012/08/08 16:24:20 [debug] 13885#0: *669 http large header copy: 693 2012/08/08 16:24:20 [debug] 13885#0: *669 recv: fd:17 214 of 7499 2012/08/08 16:24:20 [debug] 13885#0: *669 http header: "Pragma: no-cache" 2012/08/08 16:24:20 [debug] 13885#0: *669 http header: "Cache-Control: no-cache" 2012/08/08 16:24:20 [debug] 13885#0: *669 http header done 2012/08/08 16:24:20 [debug] 13885#0: *669 event timer del: 17: 1344435925526 2012/08/08 16:24:20 [debug] 13885#0: *669 generic phase: 0 2012/08/08 16:24:20 [debug] 13885#0: *669 add cleanup: 00000000014972F8 2012/08/08 16:24:20 [debug] 13885#0: *669 generic phase: 1 2012/08/08 16:24:20 [debug] 13885#0: *669 test location: "/" 2012/08/08 16:24:20 [debug] 13885#0: *669 test location: "static" 2012/08/08 16:24:20 [debug] 13885#0: *669 test location: "dynamic" 2012/08/08 16:24:20 [debug] 13885#0: *669 using configuration "/" 2012/08/08 16:24:20 [debug] 13885#0: *669 http cl:-1 max:1048576 2012/08/08 16:24:20 [debug] 13885#0: *669 generic phase: 3 2012/08/08 16:24:20 [debug] 13885#0: *669 post rewrite phase: 4 2012/08/08 16:24:20 [debug] 13885#0: *669 generic phase: 5 2012/08/08 16:24:20 [debug] 13885#0: *669 add cleanup: 0000000001497330 2012/08/08 16:24:20 [debug] 13885#0: *669 generic phase: 6 2012/08/08 16:24:20 [debug] 13885#0: *669 generic phase: 7 2012/08/08 16:24:20 [debug] 13885#0: *669 access phase: 8 2012/08/08 16:24:20 [debug] 13885#0: *669 access phase: 9 2012/08/08 16:24:20 [debug] 13885#0: *669 post access phase: 10 2012/08/08 16:24:20 [debug] 13885#0: *669 try files phase: 11 2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "/forum/styles/bastisstyle/theme/stylesheet.css" 2012/08/08 16:24:20 [debug] 13885#0: *669 try to use file: "/forum/styles/bastisstyle/theme/stylesheet.css" "/srv/www/wanda.eu/forum/styles/bastisstyle/theme/stylesheet.css" 2012/08/08 16:24:20 [debug] 13885#0: *669 try file uri: "/forum/styles/bastisstyle/theme/stylesheet.css" 2012/08/08 16:24:20 [debug] 13885#0: *669 malloc: 000000000152A140:4096 2012/08/08 16:24:20 [debug] 13885#0: *669 http init upstream, client timer: 0 2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "QUERY_STRING" 2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "QUERY_STRING: " 2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "REQUEST_METHOD" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "GET" 2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "REQUEST_METHOD: GET" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "CONTENT_TYPE" 2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "CONTENT_TYPE: " 2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "CONTENT_LENGTH" 2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "CONTENT_LENGTH: " 2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "SCRIPT_NAME" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "/forum/styles/bastisstyle/theme/stylesheet.css" 2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "SCRIPT_NAME: /forum/styles/bastisstyle/theme/stylesheet.css" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "REQUEST_URI" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "/forum/styles/bastisstyle/theme/stylesheet.css" 2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "REQUEST_URI: /forum/styles/bastisstyle/theme/stylesheet.css" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "DOCUMENT_URI" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "/forum/styles/bastisstyle/theme/stylesheet.css" 2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "DOCUMENT_URI: /forum/styles/bastisstyle/theme/stylesheet.css" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "DOCUMENT_ROOT" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "/srv/www/wanda.eu" 2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "DOCUMENT_ROOT: /srv/www/wanda.eu" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "SERVER_PROTOCOL" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "HTTP/1.1" 2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "SERVER_PROTOCOL: HTTP/1.1" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "GATEWAY_INTERFACECGI/1.1" 2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "GATEWAY_INTERFACE: CGI/1.1" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "SERVER_SOFTWARE" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "nginx/" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "0.7.67" 2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "SERVER_SOFTWARE: nginx/0.7.67" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "REMOTE_ADDR" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "95.130.252.148" 2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "REMOTE_ADDR: 95.130.252.148" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "REMOTE_PORT" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "62676" 2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "REMOTE_PORT: 62676" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "SERVER_ADDR" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "109.75.187.90" 2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "SERVER_ADDR: 109.75.187.90" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "SERVER_PORT" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "81" 2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "SERVER_PORT: 81" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "SERVER_NAME" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "www.wanda.eu" 2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "SERVER_NAME: www.wanda.eu" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "REDIRECT_STATUS200" 2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "REDIRECT_STATUS: 200" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "SCRIPT_FILENAME" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script copy: "/srv/www/wanda.eu" 2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "/forum/styles/bastisstyle/theme/stylesheet.css" 2012/08/08 16:24:20 [debug] 13885#0: *669 fastcgi param: "SCRIPT_FILENAME: /srv/www/wanda.eu/forum/styles/bastisstyle/theme/stylesheet.css" 2012/08/08 16:24:20 [debug] 13885#0: *669 http cleanup add: 000000000152A9E8 2012/08/08 16:24:20 [debug] 13885#0: *669 get rr peer, try: 1 2012/08/08 16:24:20 [debug] 13885#0: *669 socket 44 2012/08/08 16:24:20 [debug] 13885#0: *669 epoll add connection: fd:44 ev:80000005 2012/08/08 16:24:20 [debug] 13885#0: *669 connect to unix:/tmp/php-cgi/php-cgi.socket, fd:44 #684 2012/08/08 16:24:20 [debug] 13885#0: *669 connected 2012/08/08 16:24:20 [debug] 13885#0: *669 http upstream connect: 0 2012/08/08 16:24:20 [debug] 13885#0: *669 http upstream send request 2012/08/08 16:24:20 [debug] 13885#0: *669 chain writer buf fl:0 s:1816 2012/08/08 16:24:20 [debug] 13885#0: *669 chain writer in: 000000000152AA20 2012/08/08 16:24:20 [debug] 13885#0: *669 writev: 1816 2012/08/08 16:24:20 [debug] 13885#0: *669 chain writer out: 0000000000000000 2012/08/08 16:24:20 [debug] 13885#0: *669 event timer add: 44: 60000:1344435920767 2012/08/08 16:24:20 [debug] 13885#0: *669 http run request: "/forum/styles/bastisstyle/theme/stylesheet.css?" 2012/08/08 16:24:20 [debug] 13885#0: *669 http upstream check client, write event:1, "/forum/styles/bastisstyle/theme/stylesheet.css" 2012/08/08 16:24:20 [debug] 13885#0: *669 http upstream recv(): -1 (11: Resource temporarily unavailable) 2012/08/08 16:24:20 [debug] 13885#0: *669 http upstream request: "/forum/styles/bastisstyle/theme/stylesheet.css?" 2012/08/08 16:24:20 [debug] 13885#0: *669 http upstream process header 2012/08/08 16:24:20 [debug] 13885#0: *669 malloc: 000000000152FAB0:32768 2012/08/08 16:24:20 [debug] 13885#0: *669 recv: fd:44 12488 of 32768 2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi record byte: 01 2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi record byte: 06 2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi record byte: 00 2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi record byte: 01 2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi record byte: 1F 2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi record byte: F8 2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi record byte: 00 2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi record byte: 00 2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi record length: 8184 2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi parser: 0 2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi header: "X-Powered-By: PHP/5.3.3-7+squeeze13" 2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi parser: 0 2012/08/08 16:24:20 [debug] 13885#0: *669 http fastcgi header: "Content-type: text/html"
….和更多的行,这表明它是由nginx发出的。
问题在这里,内容types设置为text / html,非常清楚,PHP解释器运行样式表,这是绝对不必要的。
特别是这些线路在这里引起我的一个循环:
2012/08/08 16:24:20 [debug] 13885#0: *669 http script var: "/forum/styles/bastisstyle/theme/stylesheet.css" 2012/08/08 16:24:20 [debug] 13885#0: *669 try to use file: "/forum/styles/bastisstyle/theme/stylesheet.css" "/srv/www/wanda.eu/forum/styles/bastisstyle/theme/stylesheet.css" 2012/08/08 16:24:20 [debug] 13885#0: *669 try file uri: "/forum/styles/bastisstyle/theme/stylesheet.css"
nginx正在寻找正确的文件在正确的位置,但似乎没有认出它。 这不是一个权限问题,因为我可以打开文件,当我的数据用户(这是nginx用户)。
这里的任何帮助,为什么服务器显示这种行为,将不胜感激。
最好的问候,延斯
编辑1
我想我自己解决了这个问题,虽然我没有真正的知道这个configuration和第一个configuration有什么不同,为什么第一个configuration示例中的行为就像我描述的那样。 我试图解决与该网站有关的另一个问题,并修复了样式表的问题。
这里是工作的configuration:
server { listen 81; ## listen for ipv4 listen [::]:81 default ipv6only=on; ## listen for ipv6 server_name www.wanda.eu; access_log /var/log/nginx/wanda.eu.access.log; error_log /var/log/nginx/wanda.eu.error.log debug; root /srv/www/wanda.eu; index index.php index.html; location /static { try_files $uri $uri/ @php_index =404; expires 24h; } location / { try_files $uri $uri/ $uri/index.html $uri/index.htm @php; } location /dynamic { try_files $uri $uri/ /dynamic/index.php =404; include /etc/nginx/fastcgi_params; fastcgi_index index.php; fastcgi_pass unix:/tmp/php-cgi/php-cgi.socket; fastcgi_param SCRIPT_FILENAME /srv/www/wanda.eu$fastcgi_script_name; } location @php { try_files $uri /index.php =404; include /etc/nginx/fastcgi_params; fastcgi_index index.php; fastcgi_pass unix:/tmp/php-cgi/php-cgi.socket; fastcgi_param SCRIPT_FILENAME /srv/www/wanda.eu$fastcgi_script_name; } location ~ \.php$ { try_files $uri /index.php =404; include /etc/nginx/fastcgi_params; fastcgi_index index.php; fastcgi_pass unix:/tmp/php-cgi/php-cgi.socket; fastcgi_param SCRIPT_FILENAME /srv/www/wanda.eu$fastcgi_script_name; } }
你的问题的答案是,你告诉nginx总是运行PHP,每当请求匹配的位置。 不pipe是什么types的文件。 让我详细说一下。
location / { fastcgi_pass php; }
现在任何匹配这个位置的东西都会被PHP处理,无论如何。
location / { try_files $uri /index.php; fastcgi_pass php; }
这不会改变任何东西! 如果$ uri匹配,nginx将继续并处理fastcgi_pass php; 指示。 如果$ uri不存在,它将执行一个内部redirect到/index.php继续并处理fastcgi_pass php; 指示。
location / { try_files $uri @php; } location @php { fastcgi_pass php; }
那么这个变化很大 如果$ uri匹配,则没有任何可处理的内容,所以nginx将简单地返回文件。 如果$ uri不匹配,nginx会继续查看命名的位置@php ,然后转到那个位置,然后遇到fastcgi_pass php; 指令,这当然会处理。
这应该回答你的具体问题。 你已经find了解决scheme,但是我认为这可能是你感兴趣的原因。