※[Ubuntu + Nginx1.24.0(hc) + php8.1-fpm + MariaDB] 종합(표준경로설치)
페이지 정보
작성자 sbLAB 댓글 0건 조회 699회 작성일 23-06-21 22:30본문
■1) Ubuntu22.04 + nginx-1.24.0 + nginx_upstream_check_module 컴파일 설치(표준경로)
※ 기존 xampp, mysql(mariaDB) 모두 삭제 후 설치시작.
※ nginx_upstream_check_module 때문에 compile 설치한 것으로, 일반적인 웹서버는 apt install nginx 로 표준 설치(certbot 호환 등 경로 문제없음 )
※ 컴파일 설치인 경우에도 아래 Configuring NGINX Paths 목록 참고하여 apt install nginx 표준 설치 경로 파라미터로 컴파일 권장.
[표준설치 + ssl + auto ssl renew 설정은 아래 링크사용]
http://sebom.com/gb/bbs/board.php?bo_table=tech&wr_id=110
Settings
- Ubuntu22.04
- nginx-1.24.0 http://nginx.org/en/download.html
- nginx_upstream_check_module check_1.20.1+.patch (Health-Check open source) https://github.com/yaoweibin/nginx_upstream_check_module
- ssl(libssl-dev)
※ nginx-1.24.0 버전 + ginx_upstream_check_module 은 check_1.20.1+.patch => 버전이 정확히 일치하지 않으나 아래와 같이 컴파일 설치 진행완료.
※ nginx-1.20.1 버전 + ginx_upstream_check_module 은 check_1.20.1+.patch => 컴파일 할때,
--with-http_ssl_module SSL모듈에서 오류 발생.(설치된 libssl-dev ssl라이브러리 최신 버전(3.0)에서 Deprecated된 함수를 nginx-1.20.1 에서 사용하려 한다는 오류)
Compile Install nginx-1.24.0 버전 + nginx_upstream_check_module 은 check_1.20.1+.patch
# apt update
# cd /home/myhome
# mkdir nginx
# cd nginx
# apt install git
# git clone https://github.com/yaoweibin/nginx_upstream_check_module.git
# wget 'http://nginx.org/download/nginx-1.24.0.tar.gz'
# tar -xvf nginx-1.24.0.tar.gz
# cd nginx-1.24.0
※ 기존 check_1.20.1+.patch 패치한 nginx-1.24.0 을 그대로 사용하지 말것! 새로 tar -xvf nginx-1.24.0.tar.gz 압축해제 해서 패치 할것!
# patch -p1 < ../nginx_upstream_check_module/check_1.20.1+.patch
--------
patching file src/http/modules/ngx_http_upstream_hash_module.c
patching file src/http/modules/ngx_http_upstream_ip_hash_module.c
patching file src/http/modules/ngx_http_upstream_least_conn_module.c
patching file src/http/ngx_http_upstream_round_robin.c
patching file src/http/ngx_http_upstream_round_robin.h
---------
# gcc --version
--------------
Command 'gcc' not found
--------------
# apt install gcc
# apt install build-essential
# apt install libpcre3-dev
# apt install zlib1g-dev
# apt install libssl-dev // --with-http_ssl_module 에 사용될 ssl 라이브러리
-------------
※위 gcc 설치 과정에서 아래오류! libc6=2.35-0ubuntu3 버전이 필요하다는 뜻!
The following packages have unmet dependencies:
libc6-dev : Depends: libc6 (= 2.35-0ubuntu3) but 2.35-0ubuntu3.1 is to be installed
-------------
# apt install libc6=2.35-0ubuntu3
# gcc --version
-----------
gcc (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0
-----------
Configuring NGINX Paths - 설치경로 설정 Parameter 들 정보
https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/
meter | Description |
---|---|
--prefix=<PATH> | Directory for NGINX files, and the base location for all relative paths set by the other
to the nginx.conf configuration file. Default: /usr/local/nginx. |
--sbin-path=<PATH> | Name of the NGINX executable file, which is used only during installation. Default: **/sbin/nginx |
--conf-path=<PATH> | Name of the NGINX configuration file. You can, however, always override this value at startup by specifying a different file with the |
--pid-path=<PATH> | Name of the nginx.pid file, which stores the process ID of the After installation, the path to the filename can be changed with the pid directive in the NGINX configuration file. Default: **/logs/nginx.pid |
--error-log-path=<PATH> | Name of the primary log file for errors, warnings, and diagnostic data. After installation, the filename can be changed with the error_log directive in the NGINX configuration file. Default: **/logs/error.log |
--http-log-path=<PATH> | Name of the primary log file for requests to the HTTP server. After installation, the filename can always be changed with the access_log directive in the NGINX configuration file. Default: **/logs/access.log |
--user=<NAME> | Name of the unprivileged user whose credentials are used by the NGINX worker processes. After installation, the name can be changed with the user directive in the NGINX configuration file. Default: |
--group=<NAME> | Name of the group whose credentials are used by the NGINX worker processes. After installation, the name can be changed with the user directive in the NGINX configuration file. Default: the value set by the |
--with-pcre=<PATH> | Path to the source for the PCRE library, which is required for regular expressions support in the location directive and the Rewrite module. |
--with-pcre-jit | Builds the PCRE library with “just-in-time compilation” support (the pcre_jit directive). |
--with-zlib=<PATH> | Path to the source for the zlib library, which is required by the Gzip module. |
아래 표준경로 형태 권장
- 아래 표준 경로 옵션 사용(certbot 등 다른 툴과 호환위함)
./configure --add-module=../nginx_upstream_check_module --with-http_ssl_module --with-http_stub_status_module --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/run/nginx.pid --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --user=nginx --group=nginx
# make
# make install
[방화벽 80, 443 허용]
# ufw enable
# ufw status
# ufw allow 80
# ufw allow 443
[nginx 웹루트 html 경로 생성] <--- 위 과정 설치 시 /etc/nginx/html 로 웹루트가 생성되어 있음.
/var/www/html
[nginx 사용자 추가]
# useradd --shell /usr/sbin/nologin --home-dir /var/www/html nginx
# cat /etc/passwd
nginx:x:1001:1001::/var/www/html:/usr/sbin/nologin
# cd /var/www
# chown nginx:nginx html -R
# cd /etc/nginx/html <--- 위 과정 설치 시 /etc/nginx/html 로 웹루트가 생성되어 있음.
# cp * /var/www/html/ <--- 웹루트로 사용할 /var/www/html/ 아래에 웹페이지들 복사
/etc/nginx/nginx.conf 메인설정파일에 root /var/www/html; 선언
# cd /usr/sbin
# ./nginx
---------------------------------------
nginx -s stop 정지
nginx -s reload 재시작
nginx -t 설정파일 체크
-----------------------------------------
/usr/lib/systemd/system/nginx.service 파일 생성
--------------------------------------------------------
[Unit]
Description=A high performance web server and a reverse proxy server
Documentation=man:nginx(8)
After=network.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid
TimeoutStopSec=5
KillMode=mixed
[Install]
WantedBy=multi-user.target
----------------------------------------------------
# systemctl daemon-reload
[자동시작 등록]
systemctl enable nginx.service
[웹서버 예시 nginx.conf 설정]
# nano /etc/nginx/nginx.conf
2) PHP8.1-FPM 세팅
[php-fpm 설치]
# apt install php-fpm
# php -v
# apt install php8.1-{bcmath,fpm,xml,mysql,zip,intl,ldap,gd,cli,bz2,curl,mbstring,pgsql,opcache,soap,cgi}
# php -m
# ps -ef | grep nginx
-----------------------
root 4935 1 0 17:36 ? 00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
nginx 4936 4935 0 17:36 ? 00:00:00 nginx: worker process
nginx 4937 4935 0 17:36 ? 00:00:00 nginx: worker process
root 4948 2651 0 17:41 pts/1 00:00:00 grep --color=auto nginx
------------------------
[경로확인]
/etc/php/8.1/fpm/php.ini <-- php.ini
/etc/nginx/nginx.conf <= nginx.conf
/run/php/php8.1-fpm.sock <= php8.1-fpm.sock 경로
/etc/php/8.1/fpm/ <= php-fpm.conf php.ini 경로
/etc/php/8.1/fpm/pool.d/www.conf <= www.conf
# nano /etc/php/8.1/fpm/pool.d/www.conf 설정
------------------------------------------------
user = nginx
group = nginx
# apt install mariadb-server mariadb-client php-mysql
[경로정보]
/var/lib/mysql <--- mysql data 디렉토리 경로
/etc/mysql/my.cnf <--- mysql 설정파일들
/usr/bin <--- mysql ... mysqldump ....
# mysql_secure_installation
------------------------------
root 의 현재 비밀번호 입력(없으면 입력): root 비밀번호입력
root 암호를 설정하시겠습니까? [Y/n] y
익명 사용자를 제거하시겠습니까? [Y/n] y
원격으로 root 로그인을 허용하지 않습니까? [Y/n] n
테스트 데이터베이스를 제거하고 액세스하시겠습니까? [Y/n] n
지금 권한 테이블을 다시 로드하시겠습니까? [Y/n] y
---------------------------------
※ 리눅스 root 계정인 경우는 mysql 또는 mysql -root 만으로 mysql 접속됨.
※ 리눅스 일반유저 계정은 mysql -uroot -p루트비밀번호 입력해야 접속가능.
# apt install phpmyadmin
# find / -name phpmyadmin
--------------------------
/usr/share/phpmyadmin <--- 설치경로 확인
--------------------------
[nginx 웹루트 /usr/local/nginx/html/ 아래에 심볼릭링크 생성]
# ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
http://192.168.0.9/phpmyadmin 으로 웹접속 가능
[phpmyadmin 웹접속시 경고 표시 처리]
※(cat /etc/passwd) nginx:x:1002:1003::/var/www/html:/usr/sbin/nologin
※ /etc/nginx/nginx.conf 설정에서 user nginx; 로 변경해줌.
1) TempDir(tmp) 경고표시
2) 암호화 문자열(blowfish_secret)을 필요 경고표시
[해결]
# cd /var/lib/phpmyadmin/
# ll
-----------------
-rw-r----- 1 root www-data 68 6월 17 13:12 blowfish_secret.inc.php
drwxr-xr-x 2 www-data www-data 4096 1월 21 2022 tmp/
-----------------
# chown nginx:nginx tmp -R <- tmp 디렉토리와 그 아래 파일까지 모두 nginx 유저:그룹으로 변경해줌(OK)
# chown nginx:nginx blowfish_secret.inc.php <- nginx 유저:그룹으로 변경해줌(OK)
#ll
----------------
-rw-r----- 1 nginx nginx 68 6월 17 13:12 blowfish_secret.inc.php
drwxr-xr-x 3 nginx nginx 4096 6월 17 14:26 tmp/
----------------
#reboot 해도 mysql / php8.1-fpm 서비스 자동 시작 됨(apt 설치 할때 service에 자동 등록됨)
php8.1-fpm.service / mariadb.service ---> /usr/lib/systemd/system/ 아래에 설치 시 service 파일 생성 및 자동 시작에 등록되어 있음
nginx.service ---> /usr/lib/systemd/system/nginx.service 경로에 수동으로 생성했음.
그러나, nginx 서비스가 정상 시작이 안될 경우, 아래처럼 원인 확인 -> 80 포트를 다른 서비스가 사용 중인지 확인.
# systemctl status nginx
------------------------------------
nginx[2340]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
-------------------------------------
# netstat -ntlp | grep 80
---------------------------------------------------------------------------------------------
tcp6 0 0 :::80 :::* LISTEN 750/apache2
----------------------------------------------------------------------------------------------
[패키지 설치 중에 apache2가 함께 설치되거나, 리눅스에 기본 설치된 경우가 있음]
# apt stop apache2
# apt remove apache2
# systemctl disable apache2
/etc/systemd/system 등 아래 *.service 서비스들 위치함
/usr/lib/systemd/system/nginx.service <- nginx.service 파일 위치
# service nginx status
# service nginx restart
모니터링 --with-http_stub_status_module (위 컴파일 할때 포함 시킴 + nginx.conf 에서 nginx_status 설정함)
https://mysite.kr/nginx_status
[opcache + jit 활성화]
#nano /etc/php/8.1/fpm/php.ini
-----------------------------------
zend_extension=opcache
[opcache]
opcache.enable=1
opcache.jit_buffer_size=100M
opcache.jit=tracing
opcache.enable_cli=1
opcache.validate_timestamps=1
opcache.revalidate_freq=20
----------------------------------
- 이전글Letsencrypt add domain to existing certificate 23.06.23
- 다음글※ nginx + ssl(letsencrypt) + auto ssl renew 23.06.21
댓글목록
등록된 댓글이 없습니다.