서버 점검 안내

dsclub은 서비스의 안정성과 성능 향상을 위해
매일 04시 30분에 정기 점검이 진행됩니다.

점검 시간: 오전 4시 30분 ~ 4시 35분

해당 시간 동안 일시적으로 서비스에 접속이 불가능하오니, 양해 부탁드립니다.

우분투 nginx 설치와 php연동 (Install NGINX On Ubuntu 22.04.2 LTS (GNU/Linux 5.15.0-1028-raspi aarch64)) > 코딩 스토리

우분투 nginx 설치와 php연동 (Install NGINX On Ubuntu 22.04.2 LTS (GNU/Linux 5…

페이지 정보

작성자 profile_image tak2 (192.♡.0.1) 작성일 23-05-20 02:01 조회 9,128 댓글 1

본문

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

#​

# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#       listen 80;
#       listen [::]:80;
#
#       server_name example.com;
#
#       root /var/www/html;
#       index index.php index.html;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
#}

(2)
server {

listen 80 default_server;

listen [::]:80 default_server;

# SSL configuration

#

listen 443 ssl default_server;

listen [::]:443 ssl default_server;​
ssl on;
ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem;​

​(2)
# Add index.php to the list if you are using PHP
index index.php index.html;​

(2)
location ~ \.php$ {

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;

}​

몇몇 사용자들은 초기 설정시 fastcgi_pass unix:/var/run/php/php-fpm.sock로 되있는 경우가 있는데 
이 때 fastcgi_pass unix:/var/run/php/php-fpm.sock​를 fastcgi_pass unix:/var/run/php/php(본인이 사용하는php 버전, 괄호는 작성 안함)-fpm.sock​
로 변경한다.

ex.) fastcgi_pass unix:/var/run/php/php-fpm.sock​로 되어있는데 현재 php 8.1을 설치한 경우,
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock​ 로 변경한다.

! 중요, 

sudo vi /etc/nginx/sites-available/default​ 를 다 작성, 저장 후 나갔다면 올바른지 확인을 한다.

sudo nginx-t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful 이 뜨면 정상작동 되는 것이다

파일 변경한 것을 반영하려면, sudo systemctl restart nginx 를 하면 된다.
// sudo service nginx reroad 도 가능하다

<!---------코멘트1---------->
간단 vi 사용법

i 는 작성할 때 사용

esc 작성 완료 시 사용

:q 저장 안하고 나가기

:q! 강제로 저장 안하고 나가기

:w 저장하기

:w! 강제로 저장

:wq 저장하고 나가기

:wq! 강제로 저장하고 나가기


좋아요83 이 글을 좋아요하셨습니다
url 복사 카카오톡 공유 라인 공유 페이스북 공유 트위터 공유

2kat님의 댓글

no_profile 2kat 아이피 (000.♡.000.000) 작성일

감사합니다.

전체 269건
게시물 검색

접속자집계

오늘
1,362
어제
1,445
최대
4,271
전체
292,272