웹서버 | centOS7 + rpm + selinux nginx-1.18 + 설치
페이지 정보
작성자 전소현 작성일20-09-25 09:59 조회3,207회 댓글0건관련링크
본문
[centos7 selinux nginx-1.18 + 설치 ]
download
wget https://nginx.org/packages/rhel/7/x86_64/RPMS/nginx-1.18.0-1.el7.ngx.x86_64.rpm
1. 설치
[root@localhost] cd /tmp
[root@localhost tmp] nginx-1.18.0-1.el7.ngx.x86_64.rpm
[root@localhost tmp] yum install -y nginx [yum 이용해 설치]
[root@localhost tmp] rpm -Uvh nginx-1.18.0-1.el7.ngx.x86_64.rpm [파일받아설치]
[root@localhost tmp] vi /etc/yum.repos.d/nginx.repo [외부저장소 추가]
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
2.방화벽 포트 개방
[root@localhost tmp] firewall-cmd --permanent --zone=public --add-port=8089/tcp
[root@localhost tmp] firewall-cmd --reload
[root@localhost tmp] firewall-cmd --list-ports
3. Nginx 포트 설정
[root@localhost tmp] cd /etc/nginx/
[root@localhost nginx]
[root@localhost conf.d] vi /etc/nginx/conf.d/default.conf
upstream jeju {
server 127.0.0.1:8080;
}
server {
listen 80;
server_name localhost;
#index index.html index.htm;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
proxy_intercept_errors on;
client_max_body_size 200M;
keepalive_timeout 300;
location / {
proxy_pass http://jeju/;
}
location /api/ {
proxy_pass http://jeju/;
}
location /test/ {
proxy_pass http://127.0.0.1:8080;
}
error_page 404 /usr/share/nginx/html/index.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
[참고 1]
Reverse Proxy
location / {
sendfile off;
proxy_pass http://127.0.0.1:3000;
proxy_redirect default;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
proxy_max_temp_file_size 0;
}
http {
keepalive_timeout 65;
gzip on;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
}
client_max_body_size 200M;
server {
if ($http_x_forwarded_proto = 'http') {
return 307 https://$host$request_uri;
}
}
server {
listen 80;
server_name okdevtest.net www.okdevtest.net;
return 307 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name www.okdevtest.net okdevtest.net;
if ($host = 'www.okdevtest.net' ) {
rewrite ^/(.*)$ http://도메인.net/$1 permanent;
}
}
[참고 2] : 로드 밸런서 nginx --> [1]
--> [2]
upstream test {
ip_hash;
server 127.0.0.1:8081;
server 127.0.0.1:8082;
server 127.0.0.1:8083;
server 127.0.0.1:8084;
}
server {
listen 80;
server_name localhost;
location / {
ip_hash #아이피로 해싱해서 분배한다.
#least_conn - 연결수가 가장 적은 서버를 선택해서 분배, 근데 가중치를 고려함
#least_time - 연결수가 가자 적으면서 평균 응답시간이 가장 적은 쪽을 선택해서분배
proxy_pass http://test;
}
}
4. Nginx 데몬 실행
[root@localhost tmp] systemctl start nginx
[root@localhost tmp] systemctl enable nginx
5. 혹시 연길이 안된다면.
조치 1 : 아래 내용으로 변경해줌 SELinux 설정
vi /etc/sysconfig/selinux
SELINUX=disabled
SELINUXTYPE=targeted
download
wget https://nginx.org/packages/rhel/7/x86_64/RPMS/nginx-1.18.0-1.el7.ngx.x86_64.rpm
1. 설치
[root@localhost] cd /tmp
[root@localhost tmp] nginx-1.18.0-1.el7.ngx.x86_64.rpm
[root@localhost tmp] yum install -y nginx [yum 이용해 설치]
[root@localhost tmp] rpm -Uvh nginx-1.18.0-1.el7.ngx.x86_64.rpm [파일받아설치]
[root@localhost tmp] vi /etc/yum.repos.d/nginx.repo [외부저장소 추가]
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
2.방화벽 포트 개방
[root@localhost tmp] firewall-cmd --permanent --zone=public --add-port=8089/tcp
[root@localhost tmp] firewall-cmd --reload
[root@localhost tmp] firewall-cmd --list-ports
3. Nginx 포트 설정
[root@localhost tmp] cd /etc/nginx/
[root@localhost nginx]
[root@localhost conf.d] vi /etc/nginx/conf.d/default.conf
upstream jeju {
server 127.0.0.1:8080;
}
server {
listen 80;
server_name localhost;
#index index.html index.htm;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
proxy_intercept_errors on;
client_max_body_size 200M;
keepalive_timeout 300;
location / {
proxy_pass http://jeju/;
}
location /api/ {
proxy_pass http://jeju/;
}
location /test/ {
proxy_pass http://127.0.0.1:8080;
}
error_page 404 /usr/share/nginx/html/index.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
[참고 1]
Reverse Proxy
location / {
sendfile off;
proxy_pass http://127.0.0.1:3000;
proxy_redirect default;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
proxy_max_temp_file_size 0;
}
http {
keepalive_timeout 65;
gzip on;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
}
client_max_body_size 200M;
server {
if ($http_x_forwarded_proto = 'http') {
return 307 https://$host$request_uri;
}
}
server {
listen 80;
server_name okdevtest.net www.okdevtest.net;
return 307 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name www.okdevtest.net okdevtest.net;
if ($host = 'www.okdevtest.net' ) {
rewrite ^/(.*)$ http://도메인.net/$1 permanent;
}
}
[참고 2] : 로드 밸런서 nginx --> [1]
--> [2]
upstream test {
ip_hash;
server 127.0.0.1:8081;
server 127.0.0.1:8082;
server 127.0.0.1:8083;
server 127.0.0.1:8084;
}
server {
listen 80;
server_name localhost;
location / {
ip_hash #아이피로 해싱해서 분배한다.
#least_conn - 연결수가 가장 적은 서버를 선택해서 분배, 근데 가중치를 고려함
#least_time - 연결수가 가자 적으면서 평균 응답시간이 가장 적은 쪽을 선택해서분배
proxy_pass http://test;
}
}
4. Nginx 데몬 실행
[root@localhost tmp] systemctl start nginx
[root@localhost tmp] systemctl enable nginx
5. 혹시 연길이 안된다면.
조치 1 : 아래 내용으로 변경해줌 SELinux 설정
vi /etc/sysconfig/selinux
SELINUX=disabled
SELINUXTYPE=targeted
[주소복사] https://www.goodsweb.kr/?u=D418J9yy
SNS 알리기
핀터레스트
텔레그램로
블로그로
페이스북
트위터
카카오스토리
카톡 공유
관련 블로그
로딩중