安装配置Nginx笔记(Ubuntu16.04)
卸载命令
卸载前最好先停止服务nginx -s stop 有时候不停止 直接卸载会出现卸不掉的情况
sudo apt-
get
--purge remove nginx
有时候会发现卸载不掉
用sudo apt
-
get autoremove命令去卸载
删除Nginx相关服务
dpkg --get-selections|grep nginx
sudo apt-get --purge remove nginx
sudo apt-get --purge remove nginx-common
sudo apt-get --purge remove nginx-core
安装Nginx
apt install
-
y nginx
常用命令
查找nginx路径:whereis nginx
启动 service nginx start
查看Nginx的版本号:nginx -V
停止 nginx -s stop
退出 nginx -s quit
重启加载配置 nginx -s reload
测试配置是否正确
配置Nginx
root@ubuntu:/etc/nginx# more nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
自定义配置文件
root@ubuntu:/etc/nginx# cd conf.d/
root@ubuntu:/etc/nginx/conf.d# more cloud.conf
server {
listen 80;
root /home/app/run/html/dist;
index index.html;
error_page 404 index.html;
location /cloudac/ {
client_max_body_size 20m;
proxy_pass http://localhost:8070/cloudac/;
proxy_read_timeout 1800;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
proxy_set_header REMOTE_ADDR $remote_addr;
}
location /file/ {
alias /home/www/file/;
}
location /tool/ {
client_max_body_size 20m;
proxy_pass http://localhost:9000/tool/;
proxy_read_timeout 1800;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
proxy_set_header REMOTE_ADDR $remote_addr;
}
}