本文系统为
Ubuntu 18.04.6 LTS
默认安装的nginx为
nginx/1.14.0 (Ubuntu)
安装
代码语言:shell
复制
apt install nginx -y
配置文件目录
代码语言:shell
复制
cd /etc/nginx/
网站目录
代码语言:javascript
复制
cd /var/www/
修改配置
修改/etc/nginx/nginx.conf
修改62行
代码语言:javascript
复制
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-available/*;
反代配置
默认网站
如果未绑定的域名或ip会自动跳到这个网站
代码语言:javascript
复制
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
代码语言:javascript
复制
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
代码语言:javascript
复制
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
代码语言:javascript
复制
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_namerequest_uri;
}
location / {
proxy_pass http://localhost:8009/;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
}
}
其它命令
代码语言:javascript
复制
systemctl status nginx
systemctl stop nginx
systemctl start nginx
systemctl restart nginx
systemctl enable nginx