PHP没有';不要使用https,而是下载文件
我将nginx作为带有PHP-fpm的web服务器。我可以成功地看到我的网站使用http,但如果我使用https,我将下载索引页面,页面将不会显示 我的nginx.confPHP没有';不要使用https,而是下载文件,php,nginx,https,centos,Php,Nginx,Https,Centos,我将nginx作为带有PHP-fpm的web服务器。我可以成功地看到我的网站使用http,但如果我使用https,我将下载索引页面,页面将不会显示 我的nginx.conf user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; include /usr/share/nginx/modules/*.conf; events { worker_connectio
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
server_tokens off;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
fastcgi_read_timeout 300s;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
client_max_body_size 2M;
include /etc/nginx/conf.d/*.conf;
}
server {
listen 443 ssl;
server_name www.domain.net;
root /usr/share/nginx/html;
add_header X-Frame-Options "SAMEORIGIN";
ssl_certificate /etc/letsencrypt/live/www.domain.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.domain.net/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
ssl_prefer_server_ciphers on;
location / {
index index.php;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
和conf.d/default.conf
server {
listen 80;
server_name www.domain.net;
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
php位置标记仅存在于
listen 80
服务器块中。
因此,如果请求被发送到443
服务器块,它不会处理任何php文件。您应该将相同的php块添加到443服务器块
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
server_tokens off;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
fastcgi_read_timeout 300s;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
client_max_body_size 2M;
include /etc/nginx/conf.d/*.conf;
}
server {
listen 443 ssl;
server_name www.domain.net;
root /usr/share/nginx/html;
add_header X-Frame-Options "SAMEORIGIN";
ssl_certificate /etc/letsencrypt/live/www.domain.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.domain.net/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
ssl_prefer_server_ciphers on;
location / {
index index.php;
}
# NEW
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
## NEW
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
这可能是helpfull@pr1nc3嗯,它没有解决我的问题。你在nginx日志文件中看到任何错误吗?若有,;请将它们添加到您的原始帖子中。我使其正常工作,我需要添加
index.php index.html index.htm;位置/{try_files$uri$uri/=404;}