-
nginx - fcgiCS/웹 2023. 12. 26. 00:20
서블리을 사용하기 전에 사용했던 cgi 형태의 통신은 어떻게 작동했는지 확인해보는 글 입니다.
cgi보다 개선된 fcgi를 사용하였습니다.
nginx 설치
$ brew nginx
/opt/homebrew/etx/nginx에 설치된다.
/opt/homebrew/etx/nginx경로의 conf파일을 수정해야된다.nginx 실행
$ brew services start nginx $ brew services stop nginx
하지만 nginx 키워드로도 가능
$ nginx $ nginx -s stop $ nginx -s reload
root 설정
/opt/homebrew/etx/nginx경로의 conf파일을 수정해야된다.
서버 scope 속에서 root 경로 설정 가능하다.
서버 scope 에서 root 설정하면 location에서는 제거해야한다.#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 8080; server_name localhost; root /Users/myeonghanryu/Desktop/Study/infra/nginx; #charset koi8-r; #access_log logs/host.access.log main; location / { index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} include servers/*; }
cgi 파일 작성
/root경로/cgi 폴더에 hello.cgi 파일생성
#!/usr/bin/perl print "Content-type: text/html\n\n"; print "<html><body>Hello from CGI!</body></html>";
cgi 파일 conf 설정
location /cgi/ { fastcgi_pass 127.0.0.1:9000; # fcgiwrap가 실행되는 주소 및 포트. include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }
cgi 관련 파일 설치
perl, spawn-fcgi, nginx, fcgiwrap, perl 이것들이 필요
모두 brew로 설치 가능cgi 실행
spawn-fcgi 의 위치 확인
$ which spawn-fcgi
spawn-fcgi 실행
spawn-fcgi -a 127.0.0.1 -p 9000 -f /opt/homebrew/sbin/fcgiwrap
http://localhost:8080/cgi/hello.cgi 주소로 접근
좋아보이는 글 ( 나중에 보기)
https://dkswnkk.tistory.com/513
https://www.youtube.com/watch?v=6FAwAXXj5N0&ab_channel=%EC%9A%B0%EC%95%84%ED%95%9C%ED%85%8C%ED%81%AC'CS > 웹' 카테고리의 다른 글
정적 웹서버에서 MVC까지 (1) 2023.12.26