Nginx
安装
使用apt-get安装命令
sudo apt-get install nginx
查看nginx版本
nginx -v
启动,查看,停止,重启nginx
开启nginx服务
service nginx start
或者
sudo systemctl start nginx.service
查看nginx状态
service nginx status
或者
sudo systemctl status nginx.service
停止nginx服务
service nginx stop
sudo systemctl stop nginx.service
重启nginx服务
service nginx restart
sudo systemctl restart nginx.service
重新加载配置
nginx -s reload
配置nginx代理
cd /etc/nginx/
主要配置在nginx.conf文件中 查看 cat nginx.conf
看到配置指向了两个目录的配置文件 配置其中一个即可
配置/etc/nginx/sites-enabled
目录下的default
server {
listen 80;
server_name localhost;
location / {
root /opt/dist/;
index index.html index.htm;
}
location /api/ {
proxy_pass http://localhost:8080/;
#proxy_set_header Host $http_host;
proxy_connect_timeout 15;
proxy_send_timeout 15;
proxy_read_timeout 15;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}