Linux
具有嵌套位置以擷取 php 文件的別名指令 - 對 php 文件的請求給出 404
我有一個目錄/網路應用程序,它位於我網站的網路根目錄之外。
假設網站在這裡:
/var/www/site/htdocs/
外部應用程序位於此處:
/var/www/apps/coolapp/
我的問題是如何配置 nginx 以將所有類似
www.mysite.com/coolapp/*
(星號是萬用字元)的請求映射/路由到外部位置/var/www/apps/coolapp/
?例如,www.mysite.com/coolapp/test.php 應該是 server/var/www/apps/coolapp/test.php
。我在主文件中添加了一個
alias
指令。這適用於除 .php 文件之外的所有文件,因為還有另一個正在擷取 .php 文件。所以我用.php 文件嵌套了一個,但現在 nginx 告訴我它找不到 .php 文件“404 File Not Found”。這是目前的樣子production.conf``nginx.conf``location``location``alias``production.conf
server { listen 80; listen 443 ssl; ssl_certificate /blah/blah/blah; ssl_certificate_key /blah/blah/blah; ssl_protocols blah blah blah; ssl_ciphers blahblahblah; ssl_prefer_server_ciphers blahblah; access_log /var/log/nginx/www.mysite.com-access.log; error_log /var/log/nginx/www.mysite.com-error.log error; server_name mysite.com www.mysite.com; root /var/www/site/htdocs; include conf/magento_rewrites.conf; include conf/magento_security.conf; include /var/www/site/nginx/*.conf; #-------CODE IN QUESTION------- location /coolapp/ { alias /var/www/apps/coolapp/; location ~ \.php { # Copied from "# PHP Handler" below fastcgi_param MAGE_RUN_CODE default; fastcgi_param MAGE_RUN_TYPE store; fastcgi_param HTTPS $fastcgi_https; rewrite_log on; # By default, only handle fcgi without caching include conf/magento_fcgi.conf; } } # PHP handler location ~ \.php { ## Catch 404s that try_files miss if (!-e $request_filename) { rewrite / /index.php last; } ## Store code is defined in administration > Configuration > Manage Stores fastcgi_param MAGE_RUN_CODE default; fastcgi_param MAGE_RUN_TYPE store; fastcgi_param HTTPS $fastcgi_https; rewrite_log on; # By default, only handle fcgi without caching include conf/magento_fcgi.conf; } # 404s are handled by front controller location @magefc { rewrite ^(.*) /index.php?$query_string last; } # Last path match hands to magento or sets global cache-control location / { ## Maintenance page overrides front controller index index.html index.php; try_files $uri $uri/ @magefc; expires 24h; } }
conf/magento_fcgi.conf 看起來像這樣:
fastcgi_pass phpfpm; ## Tell the upstream who is making the request proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_redirect off; # Ensure the admin panels have enough time to complete large requests ie: report generation, product import/export proxy_read_timeout 1600s; # Ensure PHP knows when we use HTTPS fastcgi_param HTTPS $fastcgi_https; ## Fcgi Settings include fastcgi_params; fastcgi_connect_timeout 120; fastcgi_send_timeout 320s; fastcgi_read_timeout 1600s; fastcgi_buffer_size 128k; fastcgi_buffers 512 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 256k; fastcgi_intercept_errors off; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; # nginx will buffer objects to disk that are too large for the buffers above fastcgi_temp_path /tmpfs/nginx/tmp 1 2; #fastcgi_keep_conn on; # NGINX 1.1.14 expires off; ## Do not cache dynamic content
有誰看到我做錯了什麼?
啊,我想通了。我需要改變這條線
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
到
fastcgi_param SCRIPT_FILENAME /var/www/apps$fastcgi_script_name;