本文系统为
Ubuntu 18.04.6 LTS
默认安装的nginx为
nginx/1.14.0 (Ubuntu)
apt install nginx -y
cd /etc/nginx/
cd /var/www/
修改/etc/nginx/nginx.conf
修改62行
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-available/*;
默认网站
如果未绑定的域名或ip会自动跳到这个网站
server {
listen 80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
反代多个网站
网站1
server {
listen 80;
server_name demo.xxx.love;
location / {
proxy_pass http://localhost:9000/;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
}
}
网站2
server {
listen 80;
server_name demo2.xxx.love;
location / {
proxy_pass http://localhost:9000/;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
}
}
ssl
server {
listen 80;
listen 443 ssl;
server_name pay.xxx.love;
ssl_certificate /etc/nginx/cert.pem;
ssl_certificate_key /etc/nginx/key.pem;
location /auth {
root /var/www/faka;
index index.html;
}
if ($scheme != "https") {
return 301 https://$server_name$request_uri;
}
location / {
proxy_pass http://localhost:8009/;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
}
}
systemctl status nginx
systemctl stop nginx
systemctl start nginx
systemctl restart nginx
systemctl enable nginx
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。