CentOS 8에 YOURLS 자체 호스팅 URL 단축기를 설치하는 방법
이 페이지에서
- 전제 조건
- LEMP 서버 설치
- YOURLS용 데이터베이스 만들기
- Yourls 설치
- YourLS용 Nginx 구성
- SELinux 및 방화벽 구성\n
- YourLS 액세스
- Lets Encrypt SSL로 YOURLS 보호\n
- 결론
YOURLS는 PHP로 작성된 무료 오픈 소스 자체 호스팅 URL 단축기입니다. TinyURL 또는 Bitly와 매우 유사하며 자신의 URL 단축 서비스를 실행할 수 있습니다. 또한 짧은 URL에 브랜딩을 추가할 수 있습니다. 비공개 및 공개 링크, 맞춤 URL 키워드, 클릭 내역 보고서, Ajaxed 인터페이스, Jsonp 지원 등을 포함한 다양한 기능을 제공합니다.
이 튜토리얼에서는 Lets Encrypt SSL을 사용하여 CentOS 8에 YOURLS를 설치하는 방법을 보여줍니다.
전제 조건
- CentOS 8을 실행하는 서버.\n
- 서버 IP를 가리키는 유효한 도메인 이름입니다.\n
- 루트 암호는 서버에 구성됩니다.\n
LEMP 서버 설치
먼저 서버에 Nginx, MariaDB, PHP 및 필수 PHP 확장을 설치해야 합니다. 다음 명령으로 모두 설치할 수 있습니다.
dnf install nginx mariadb-server php php-fpm php-json php-common php-mysqlnd php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath git unzip wget -y
모든 패키지가 설치되면 PHP-FPM 구성 파일 /etc/php-fpm.d/www.conf를 편집하고 사용자를 apache에서 nginx로 변경합니다.
nano /etc/php-fpm.d/www.conf
다음 줄을 변경합니다.
user = nginx group = nginx
파일을 저장하고 닫은 다음 Nginx, MariaDB, PHP-FPM 서비스를 시작하고 다음 명령을 사용하여 시스템 재부팅 시 시작할 수 있도록 합니다.
systemctl start nginx
systemctl enable nginx
systemctl start mariadb
systemctl enable mariadb
systemctl start php-fpm
systemctl enable php-fpm
완료되면 다음 단계로 진행할 수 있습니다.
YOURLS용 데이터베이스 생성
다음으로, YOURLS에 대한 데이터베이스와 사용자를 생성해야 합니다. 먼저 다음 명령을 사용하여 MariaDB에 로그인합니다.
mysql
로그인 후 다음 명령을 사용하여 데이터베이스와 사용자를 생성합니다.
MariaDB [(none)]> CREATE DATABASE yourlsdb;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON yourlsdb.* TO 'yourlsuser'@'localhost' IDENTIFIED BY 'password';
다음으로 다음 명령을 사용하여 권한을 플러시하고 MariaDB를 종료합니다.
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> \q
이 시점에서 MariaDB가 설치되고 구성됩니다.
당신의 설치
먼저 디렉터리를 Nginx 웹 루트로 변경하고 다음 명령을 사용하여 최신 버전의 YOURLS를 다운로드합니다.
cd /var/www/html
git clone https://github.com/YOURLS/YOURLS.git
그런 다음 다음 명령을 사용하여 샘플 구성 파일의 이름을 바꿉니다.
cd YOURLS/user/
cp config-sample.php config.php
다음으로 config.php 파일을 편집하고 데이터베이스 설정을 정의합니다.
nano config.php
다음 줄을 변경합니다.
/** MySQL database username */ define( 'YOURLS_DB_USER', 'yourlsuser' ); /** MySQL database password */ define( 'YOURLS_DB_PASS', 'password' ); /** The name of the database for YOURLS ** Use lower case letters [a-z], digits [0-9] and underscores [_] only */ define( 'YOURLS_DB_NAME', 'yourlsdb' ); /** MySQL hostname. ** If using a non standard port, specify it like 'hostname:port', eg. 'localhost:9999' or '127.0.0.1:666' */ define( 'YOURLS_DB_HOST', 'localhost' ); /** MySQL tables prefix ** YOURLS will create tables using this prefix (eg `yourls_url`, `yourls_options`, ...) ** Use lower case letters [a-z], digits [0-9] and underscores [_] only */ define( 'YOURLS_DB_PREFIX', 'yourls_' ); define( 'YOURLS_SITE', 'http://yourls.example.com' ); $yourls_user_passwords = array( 'admin' => 'yourpassword',
완료되면 파일을 저장하고 닫습니다. 그런 다음 다음 명령을 사용하여 .htaccess 파일을 만듭니다.
nano /var/www/html/YOURLS/.htaccess
다음 줄을 추가합니다.
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.*$ /yourls-loader.php [L] </IfModule>
파일을 저장하고 닫은 후 다음 명령을 사용하여 적절한 권한과 소유권을 부여하십시오.
chown -R nginx:nginx /var/www/html/YOURLS
chmod -R 775 /var/www/html/YOURLS
완료되면 다음 단계로 진행할 수 있습니다.
YOURLS용 Nginx 구성
다음으로 YOURLS에 대한 새 Nginx 가상 호스트 구성 파일을 만듭니다.
nano /etc/nginx/conf.d/yourls.conf
다음 줄을 추가합니다.
server { listen 80; server_name yourls.example.com; root /var/www/html/YOURLS; index index.php index.html index.htm; location / { try_files $uri $uri/ /yourls-loader.php$is_args$args; } location ~ \.php$ { include fastcgi.conf; fastcgi_index index.php; fastcgi_pass unix:/run/php-fpm/www.sock; } }
파일을 저장하고 닫은 후 다음 명령을 사용하여 Nginx 및 PHP-FPM 서비스를 다시 시작합니다.
systemctl restart nginx
systemctl restart php-fpm
다음 명령을 사용하여 Nginx의 상태를 확인할 수도 있습니다.
systemctl status nginx
다음과 같은 결과가 표시되어야 합니다.
? nginx.service - The nginx HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) Drop-In: /usr/lib/systemd/system/nginx.service.d ??php-fpm.conf Active: active (running) since Tue 2020-10-20 09:37:40 EDT; 5min ago Process: 12864 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS) Process: 12862 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS) Process: 12860 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS) Main PID: 12871 (nginx) Tasks: 3 (limit: 12523) Memory: 5.5M CGroup: /system.slice/nginx.service ??12871 nginx: master process /usr/sbin/nginx ??12872 nginx: worker process ??12873 nginx: worker process Oct 20 09:37:40 centos systemd[1]: Stopped The nginx HTTP and reverse proxy server. Oct 20 09:37:40 centos systemd[1]: Starting The nginx HTTP and reverse proxy server... Oct 20 09:37:40 centos nginx[12862]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok Oct 20 09:37:40 centos nginx[12862]: nginx: configuration file /etc/nginx/nginx.conf test is successful Oct 20 09:37:40 centos systemd[1]: Started The nginx HTTP and reverse proxy server.
SELinux 및 방화벽 구성
기본적으로 SELinux는 CentOS 8에서 활성화되어 있습니다. 따라서 YOURLS 웹사이트에 맞게 구성해야 합니다.
다음 명령을 사용하여 SELinux를 구성할 수 있습니다.
setsebool httpd_can_network_connect on -P
chcon -R -u system_u -t httpd_sys_rw_content_t -r object_r /var/www/html/YOURLS
그런 다음 다음 명령을 사용하여 방화벽을 통해 포트 80 및 443을 허용합니다.
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
완료되면 다음 단계로 진행할 수 있습니다.
귀하의 액세스
이제 웹 브라우저를 열고 URL http://yourls.example.com/admin을 사용하여 YOURLS에 액세스하십시오. 다음 페이지가 표시됩니다.
귀하의 설치 버튼을 클릭하십시오. 다음 페이지가 표시됩니다.
"YOURLS 관리 페이지”를 클릭하십시오. YOURLS 로그인 페이지가 표시되어야 합니다.
config.php에서 정의한 관리자 사용자 이름과 암호를 제공한 다음 로그인 버튼을 클릭합니다. 다음 페이지에 YOURLS 대시보드가 표시되어야 합니다.
Lets Encrypt SSL로 YourLS 보호
다음으로 시스템에 Certbot 유틸리티를 설치하여 YOURLS 웹사이트용 Lets Encrypt SSL을 다운로드하고 설치해야 합니다.
다음 명령을 사용하여 Certbot 클라이언트를 설치할 수 있습니다.
wget https://dl.eff.org/certbot-auto
mv certbot-auto /usr/local/bin/certbot-auto
chown root /usr/local/bin/certbot-auto
chmod 0755 /usr/local/bin/certbot-auto
다음으로, 다음 명령을 사용하여 YOURLS 웹사이트에 대한 SSL 인증서를 가져와 설치합니다.
certbot-auto --nginx -d yourls.example.com
위의 명령은 먼저 서버에 필요한 모든 종속성을 설치합니다. 설치가 완료되면 아래와 같이 이메일 주소를 제공하고 서비스 약관에 동의하라는 메시지가 표시됩니다.
Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator nginx, Installer nginx Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must agree in order to register with the ACME server at https://acme-v02.api.letsencrypt.org/directory - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (A)gree/(C)ancel: A - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Would you be willing to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about our work encrypting the web, EFF news, campaigns, and ways to support digital freedom. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: Y Obtaining a new certificate Performing the following challenges: http-01 challenge for yourls.example.com Waiting for verification... Cleaning up challenges Deploying Certificate to VirtualHost /etc/nginx/conf.d/yourls.conf
아래와 같이 HTTP 트래픽을 HTTPS로 리디렉션할지 여부를 선택합니다.
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: No redirect - Make no further changes to the webserver configuration. 2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for new sites, or if you're confident your site works on HTTPS. You can undo this change by editing your web server's configuration. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
2를 입력하고 Enter를 눌러 계속하십시오. 설치가 성공적으로 완료되면 다음과 같은 결과가 표시됩니다.
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/yourls.conf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Congratulations! You have successfully enabled https://yourls.example.com You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=yourls.example.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/yourls.example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/yourls.example.com/privkey.pem Your cert will expire on 2020-06-11. To obtain a new or tweaked version of this certificate in the future, simply run certbot-auto again with the "certonly" option. To non-interactively renew *all* of your certificates, run "certbot-auto renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le
이제 URL https://yourls.example.com을 사용하여 안전하게 YOURLS 웹사이트에 액세스할 수 있습니다.
결론
축하합니다! Nginx와 함께 YOURLS를 성공적으로 설치했으며 CentOS 8에서 Lets Encrypt SSL을 사용했습니다. 이제 YOURLS를 사용하여 자신의 URL 단축기를 쉽게 호스팅할 수 있습니다. 궁금한 점이 있으면 언제든지 문의해 주세요.