728x90
반응형
* 파일을 나누지않고 한 파일(default)에서 작업했음
* http://도메인 접근, www도메인 접근, 서브도메인 접근시 메인도메인으로 Redirect 예시임
vim /etc/nginx/sites-available/default
Main Domain ( listen 443 port )
server {
root /RootD;
index index.html index.htm index.nginx-debian.html index.php;
/* Main Domain */
server_name MainDomain;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/landmarking.kr/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/landmarking.kr/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
Sub Domain ( listen 443 port ) < REDIRECT >
server {
listen 443 ssl;
server_name SubDomain.kr www.MainDomain.co.kr www.SubDomain.kr;
return 301 https://MainDomain.co.kr$request_uri;
}
http -> https ( listen 80 port) < REDIRECT >
server {
if ($host = MainDomain.co.kr) {
return 301 https://$host$request_uri;
}
if ($host = SubDomain.kr) {
rewrite ^/(.*)$ https://MainDomain.co.kr/$request_uri;
}
listen 80 default_server;
listen [::]:80 default_server;
server_name MainDomain.co.kr SubDomain.kr;
return 404;
}
nginx -t 문제없으면
service nginx restart
728x90
반응형
'WebServer' 카테고리의 다른 글
Nginx에 php, nodejs 같이 쓰기 (0) | 2021.05.17 |
---|
댓글