1. pfx 파일을 crt 및 rsa로 변환 - convert pfx file to crt and rsa.

 $ openssl pkcs12 -in ssl.mysite.com.pfx  -clcerts -nokeys -out ssl.mysite.com.crt
 $ openssl pkcs12 -in ssl.mysite.com.pfx -nocerts -nodes -out ssl.mysite.com.rsa


2. crt rsa파일 복사 - copy crt and rsa file to NGINX_HOME/conf/ssl/

C:\Users\fehead> dir /w C:\nginx\conf\ssl

C:\nginx\conf\ssl
[.]                 [..]                ssl.mysite.com.crt   ssl.mysite.com.rsa
C:\Users\fehead>




3. nginx config 파일 설정 - set nginx config file.

######################################################################################################################################################
### nginx config.

# tomcat

upstream    tomcat {
    server    127.0.0.1:8080    fail_timeout=0;
}

# ssl.mysite.com https setting
server {
        server_name ssl.mysite.com;

        location / {
                proxy_redirect off;
                proxy_pass_header Server;

                proxy_set_header Host $http_host;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header X-Forwarded-Port $server_port;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Scheme $scheme;
                proxy_pass http://tomcat;
                charset utf-8;
        }

    listen [::]:443 ssl;
    listen 443 ssl;
    ssl on;
    ssl_certificate    ssl/ssl.mysite.com.crt;
    ssl_certificate_key    ssl/ssl.mysite.com.rsa;

}


# ssl.mysite.com SSL redirect
server {
    listen 80;
    listen [::]:80;

    server_name ssl.mysite.com;   

    return 301 https://$host$request_uri;   
}


# Etc Site
server {
    listen 80;
    listen [::]:80;

    server_name etc.mysite.com;   
    ...

}



4. test nginx config

C:\nginx>nginx.exe -t
nginx: the configuration file C:\nginx/conf/nginx.conf syntax is ok
nginx: configuration file C:\nginx/conf/nginx.conf test is successful

C:\nginx>


5. restart nginx


C:\nginx>nginx.exe -s reload


http://fehead.tistory.com/216 참고


1. 여기서  http://freedns.afraid.org/ FREE 동적 DNS를 먼저 구한다.


동적DNS를 무료로 사용해보자 - FreeDNS - 여기를 참고 하라.



2. freedns 에서 키값을 얻는다.

http://freedns.afraid.org/dynamic/ 에 들어가서 중앙 하단 부분에 자기가 등록한 도메인이 있을 것이고 그 아래쪽에 Direct URL 를 클릭하면 새창이 뜬다.



 






여기서 나온 URL부분에

빨간 상자 부분이 키 값이다.


3. Padavan 설정





고급설정 -> WAN ->DDNS 메뉴로 간다음

DDNS 클라이언트 활성화

서버 프로필을 "freedns.afraid.org" 선택

호스트에 "freedns.afraid.org"

토큰에 freedns.afraid.org  에서 얻은 키값을 넣는다.

보안 HTTPS 연결을 사용 하시겠습니까? "아니오" 선택

적용 버튼을 누른다.



라즈베리파이2에 usb 무선동굴이를 설치하고 무선공유기에 접속해서 쓰고 있다.


동굴이는 EFM ipTIME N100mini usb 2.0 를 사다가 끼웠다.


무선공유기 ssid가 myssid 이고 비밀번호가 mypassword이면 아래와 같이 하고 재부팅 하면 된다.


$ sudo -i

# rpi-update

# wpa_passphrase myssid mypassword >>  /etc/wpa_supplicant/wpa_supplicant.conf

# vi /etc/wpa_supplicant/wpa_supplicant.conf


/etc/wpa_supplicant/wpa_supplicant.conf 수정.

# /etc/wpa_supplicant/wpa_supplicant.conf

country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1         # 추가
ap_scan=1               # 추가.

network={
        ssid="myssid"
        scan_ssid=1              # 마지막에 추가된 myssid란에 추가.
        #psk="mypassword"
        psk=2f0568b3492812bd56b946dbaf3fd7dd669b9a4602a09aa6462ff057949b025c
}
 


재부팅

# reboot


postfix 메일서버 설치 방법


$ sudo -i

# apt install postfix

# vi /etc/postfix/main.cf

mynetworks = 127.0.0.0/8 192.168.0.0/24  # 192.168.0.0/24 - 메일을 보낼수 있는 ip 대역 추가.

# systemctl enable postfix.service

# systemctl start postfix.service

# mail -s "email title" user@test.com

mail test...

ctrl + d


#

 



tomcat 서버설정
Server.xml을 설정합니다.


[설정방법]
< Connector port="포트번호" protocol="HTTP/1.1" SSLEnabled="true"
               maxThread="150" scheme="https" secure="true"
               keystoreFile="pfx파일경로" keystorePass="pfx패스워드" keystoreType="PKCS12"
               clientAuth="false" sslProtocol="TLS" />


[설정예제]  
< Connector port="443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThread="150" scheme="https" secure="true"
               keystoreFile="/etc/tomcat/ssl/example.com.pfx" keystorePass="123456" keystoreType="PKCS12"
               clientAuth="false" sslProtocol="TLS" />



URL : https://www.comodossl.co.kr/certificate/ssl-installation-guides/Tomcat-pfx.aspx

가상환경 설정

$ cd /my/working/dir

$ virtualenv -p python3 env35

$ cd env35

$ mkdir run

$ source bin/activate

$ pip install django gunicorn

$ django-admin startproject testproject

$ cd testproject

$ django-admin startapp testapp


디렉토리 구조

/my/working/dir


`-- env35
    |-- bin
    |  
    |-- include
    |   `-- python3.5m -> /usr/include/python3.5m
    |-- lib
    |   `-- python3.5
    |-- testproject
    |   |-- media
    |   |-- testproject
    |   |-- static
    |   |-- templates
    |   `-- testapp
    `-- run



gunicorn systemd 등록

$ sudo mkdir /run/gunicorn

$ sudo chown youurUserName.yourGroup /run/gunicorn

# sudo vi /etc/systemd/system/gunicorn.service

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
PIDFile=/run/gunicorn/pid
User=youurUserName
Group=yourGroup
WorkingDirectory=/my/working/dir/env35/testproject
ExecStart=/my/working/dir/env35/bin/gunicorn \
        --pid /run/gunicorn/pid \
        --workers 2 \
        --bind unix:/run/gunicorn/gunicorn.sock \
        testproject.wsgi:application

ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target


gunicorn 서비스 시작

$ sudo systemctrl enable gunicorn.service

$ sudo systemctl start gunicorn.service



# 가상환경 설정

$ virtualenv -p python3 env35

$ cd envDjango

$ mkdir run

$ source bin/activate

$ pip install django gunicorn

$ django-admin startproject testproject

$ cd testproject

$ django 작업

$ cat << EOF > gunicorn_cfg.py
daemon=True
bind='unix:/your/dir/env35/run/gunicorn.sock'
workers=3
EOF

$ gunicorn -c gunicorn_cfg.py testproject.wsgi:application

$ sudo -i

# apt install nginx

# cd /etc/nginx/sites-available/

# cat << EOF > testproject_conf
server {
        listen 80;
        server_name    ${YOUR_SERVER_NAME};
        root        /usr/share/nginx/html;

        location = /favicon.ico { access_log off; log_not_found off; }

        location /static {
                root    root ${YOUR_PROJECT_DIR};
        }

        location / {
                include proxy_params;
                proxy_pass http://unix:/your/dir/env35/run/gunicorn.sock;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
}
EOF

# cd ../sites-enabled/

# ln -s ../sites-available/testproject_conf

# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

# nginx -s reload



아래에 링크에 자세한 설명

http://dveamer.github.io/backend/PythonWAS.html

/etc/ssh/sshd_config 파일를 수정하고 재시작

# /etc/ssh/sshd_config

UseDNS no  # 추가


# 위의것으도 안되면

GSSAPIAuthentication no  # 이것추가.
GSSAPICleanupCredentials yes # 이것추가.


위의 방법이 안된다면..

systemd-logind.service 서비스를 재시작한다.

# systemctl restart systemd-logind.service


그런데 이게 재시작이 안될경우가 있다

이럴때는 systemctl 데몬을 재시작한다.

# systemctl daemon-reexec 



참고 URL : https://unix.stackexchange.com/questions/393394/systemd-logind-service-fails-to-start-when-attempting-to-return-from-rescue-tar

Error Message :

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:

...

..

Cause: java.lang.NullPointerException



solution

Fucking MsSql Table Chahge Column Attribute "NVARCHAR" to "VARCHAR"


이것때문에 2주를 고생했다..

sql은 분명히 맞는데 결과값이 null이거나 아무것도 안나온다


위 메세지가 나온다면 

Sql server 테이블 컬럼 속성중에  NVARCHAR 를 VARCHAR로 바꿔라..


nginx 설정


vi /etc/nginx/sites-available/default  에 최상단에 아래 내용 추가.

upstream        tomcat {
         server  127.0.0.1:8080  fail_timeout=0;
 }


nginx 첫번재 도메인(www.hoticel.net) 설정

# 예제 1. http://www.hoticel.net

vi /etc/nginx/sites-available/www.hoticle.net

# hoticle.net => www.hoticle.net
server {
        listen 80;
        server_name hoticle.net;
        return 301 $scheme://www.hoticle.net$request_uri;
}

# www.hoticle.net 설정
server {
        listen 80;
        listen [::]:80;

        server_name www.hoticle.net;

        # Let's Encrypt 관련 디렉토리
        location /.well-known {
                # Note that a request for /.well-known/test.html whill
                # look for /var/www/ssl-prof-rancher/.well-known/test.html
                # and not /var/www/ssl-proof/rancher/test.html
                root /var/www/ssl-proof/tomcat/;
        }

        location / {
                proxy_redirect off;
                proxy_pass_header Server;

                proxy_set_header Host $http_host;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header X-Forwarded-Port $server_port;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Scheme $scheme;
                proxy_pass http://tomcat;
                charset utf-8;
        }
}
 



두번째 도메인 설정 ( www.bbb.net )

# 예제 1. http://www.bbb.net

vi /etc/nginx/sites-available/www.bbb.net

# www.bbb.net 설정
server {
        listen 80;
        listen [::]:80;

        server_name www.bbb.net;

        # Let's Encrypt 관련 디렉토리
        location /.well-known {
                # Note that a request for /.well-known/test.html whill
                # look for /var/www/ssl-prof-rancher/.well-known/test.html
                # and not /var/www/ssl-proof/rancher/test.html
                root /var/www/ssl-proof/tomcat/;
        }

        location / {
                proxy_redirect off;
                proxy_pass_header Server;

                proxy_set_header Host $http_host;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header X-Forwarded-Port $server_port;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Scheme $scheme;
                proxy_pass http://tomcat;
                charset utf-8;
        }




# nginx 문법 테스트

nginx -t

# nginx 재시작

systemctl restart nginx.service



Tomcat 설정


server.xml 설정

vi /etc/tomcat/server.xml

 <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               URIEncoding="UTF-8"
               address="127.0.0.1"
               redirectPort="8443" />

...


       <Host name="www.hoticle.net" appBase="/var/www/Hoticle" autoDeploy="true"  xmlValidation="false" xmlNamespaceAware="false">
              <Context path="/" docBase="" reloadable="true" />
      </Host>
      <Host name="www.bbb.net" appBase="/var/www/bbb" autoDeploy="true"  xmlValidation="false" xmlNamespaceAware="false">
              <Context path="/" docBase="" reloadable="true" />
      </Host>


  </Engine>

  </Service>
</Server> 



# tomcat 재실행

systemctl restart tomcat8.service



Let's Encrypt

Let's Encrypt  실행

# certbot --nginx -d www.hoticel.net -d www.bbb.net



crontab 등록

# Let's Encrypt
30 2 * * * certbot renew --noninteractive --renew-hook "/bin/systemctl reload nginx" >> /var/log/le-renew.log



참고 사이트 :

https://tom.busby.ninja/letsecnrypt-nginx-reverse-proxy-no-downtime/
https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-debian-8

+ Recent posts