[英]PHP script on AWS EC2 NGINX not working but download
我正在嘗試使用nginx在AWS ec2中設置我的網站。 這是我的nginx.conf
:
include /etc/nginx/conf.d/*.conf;
index index.php index.html index.htm;
autoindex off;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name 127.0.0.1;
root /usr/share/nginx/myproject;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
#location / {
#}
location = /index.php {
rewrite ^(.*)$ /app/index.php break;
}
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /app/index.php break;
}
}
location ~ \.(secret|salt|engine|inc|po|sh|bat|cmd|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|inc)$ {
deny all;
}
# redirect server error pages to the static page /40x.html
#
error_page 404 /404.html;
location = /40x.html {
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
try_files $uri =404
root /usr/share/nginx/myproject;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
當我訪問公共DNS時,我得到了下載,而不是運行PHP腳本。 我的nginx配置有問題嗎?
您的rewrite...break
語句應該被rewrite...last
因為PHP文件需要在其他位置處理。 有關詳細信息,請參見此文檔 。
例如:
location / {
if (!-e $request_filename){
rewrite ^ /app/index.php last;
}
}
但是,以上功能通常實現為:
location / {
try_files $uri $uri/ /app/index.php;
}
其他問題包括:
失蹤;
在try_files
語句之后的location ~ \\.php$
塊中。
location ~ \\.php$
塊中的root
語句應刪除,因為這是不必要的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.