Linux
[Nginx] conf 설정 후 index.php 접속시 파일이 다운로드 될때
먹세
2021. 5. 8. 16:20
nginx 설정을 마치고 사이트 접속 시, 접속이 제대로 안되고 index.php 파일이 다운로드 될 때,
3가지정도 살펴보면 된다.
1. fastcgi 설정
/etc/nginx/conf.d/mydomain.conf 등으로 자신의 서버가 설정되어 있을 것이다.
아래와 같이 fastcgi 부분을 확인
server {
listen 80;
server_name mydomain.com www.mydomain.com;
access_log /var/log/nginx/mydomain.com.access.log main;
error_log /var/log/nginx/mydomain.com.error.log;
root /home/www;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$query_string;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/www;
}
location ~ \.php$ {
root /home/www;
try_files $uri = 404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 16k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
}
2. default_type 확인
user nginx;
worker_processes 7;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type text/html;
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;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
client_max_body_size 50M;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
http{} 블럭 안에보면 default_type 이 기본적으로 application/octet-stream; 으로 설정되어있을 것이다.
이것을 text/html;로 변경해준다.
3. 접속시 https:// 로 접속
실제로 listen 80 만 세팅해서 ssl 세팅이 없더라도
요즘 크롬등 브라우저의 보안 특성상 http:// 로 접속하게되면 제대로 접속이 안되고 파일다운로드가 되어버리는 것 같았다.
https:// 로 접속 후 보안경고가 나오면 고급을 눌러서 안전하지 않은 페이지 실행으로 들어가면 접속 된다.
4. 위 사항들을 변경하고 나면 아래 두가지 프로세스를 모두 리스타트 해준다.
systemctl restart nginx
systemctl restart php-fpm
반응형