본문 바로가기
SW/Apache

우분투 (Ubuntu) 22.04 nginx + Apache 동시 사용하기

by bigju 2023. 8. 23.

1. nginx apache 포트 체크 및 에러

netstat -tnlp


2. nginx 서비스 중 apache 서비스 시작 오류 

* nginx apache 2개 서비스는 기본적으로 80포트를 이용하기 때문에 충돌이 발생하면서 오류 발생

root@bigju:~# systemctl start apache
Failed to start apache.service: Unit apache.service not found.
root@bigju:~# /etc/init.d/ap
apache2              apache-htcacheclean  apparmor             apport               
root@bigju:~# /etc/init.d/apache2 start
Starting apache2 (via systemctl): apache2.serviceJob for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xeu apache2.service" for details.
 failed!
root@bigju:~# systemctl status apache2
× apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Wed 2023-08-23 05:11:42 UTC; 31s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 4519 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)
        CPU: 20ms

Aug 23 05:11:42 bigju apachectl[4522]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this m>
Aug 23 05:11:42 bigju apachectl[4522]: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
Aug 23 05:11:42 bigju apachectl[4522]: (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
Aug 23 05:11:42 bigju apachectl[4522]: no listening sockets available, shutting down
Aug 23 05:11:42 bigju apachectl[4522]: AH00015: Unable to open logs
Aug 23 05:11:42 bigju apachectl[4519]: Action 'start' failed.
Aug 23 05:11:42 bigju apachectl[4519]: The Apache error log may have more information.
Aug 23 05:11:42 bigju systemd[1]: apache2.service: Control process exited, code=exited, status=1/FAILURE
Aug 23 05:11:42 bigju systemd[1]: apache2.service: Failed with result 'exit-code'.
Aug 23 05:11:42 bigju systemd[1]: Failed to start The Apache HTTP Server.

<해결>

3. nginx 포트 변경

 

<3-1 포트 변경>

vi /etc/nginx/sites-enabled/default

 

server {
        listen 80 default_server;
        listen [::]:80 default_server;

-> 80번 포트를 3000으로 변경 

server {
        listen 3000 default_server;
        listen [::]:3000 default_server;

 


4. nginx 재시작

systemctl restart nginx //nginx 재시작

netstat -tnlp  // 포트체크

nginx가 80포트에 3000포트로 변경 확인


5. apache 재시작

systemctl restart apache2

6. 최종확인

nginx apache 두 서비스 실행 중 확인

 

netstat -tnlp // 포트 확인

tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      4756/nginx: master  
tcp6       0      0 :::3000                 :::*                    LISTEN      4756/nginx: master  
tcp6       0      0 :::80                   :::*                    LISTEN      4779/apache2        

*nginx 3000포트 

*apache 80포트 

 

Big Ju

댓글

메인으로가기


    

Big Ju

IT Engineer


항상 답을 위해 노력하는

엔지니어입니다.

 

 

    


 UP!