우분투 nginx 설치와 php연동 (Install NGINX On Ubuntu 22.04.2 LTS (GNU/Linux 5…
본문
sudo apt update && sudo apt upgrade
//시스템 업데이트/업그레이드
sudo apt install nginx
//nginx 설치
sudo apt install php7.4-fpm
//nginx는 apache와 달리 php를 자체 지원하지 않아서? 연결해주는 php-fpm(?)이 필요하다.
//php7.4가 아닌 다른 버전을 하고 싶다면 앞으로 나오는 모든 명령어의 7.4를 원하는 버전으로 변경하면 된다.
//그냥 sudo apt install php-fpm을 하면 최신버전인 8.1 또는 8.2가 설치된다.
sudo vi /etc/nginx/sites-available/default
//우분투에서 처음 nginx를 설치하면 위와 같은 경로에 설정파일? 이 생성된다.
//더 높은? 알파벳(ex. A - B -C ...)가 있으면 그것이 가장 먼저 실행됨?
(1)
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
#listen 443 ssl default_server;
#listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
#
# # With php-fpm (or other unix sockets):
#fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# Virtual Host configuration for example.com
#
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
listen 443 ssl default_server;
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
2kat님의 댓글
2kat 아이피 (000.♡.000.000) 작성일감사합니다.