Ubuntu 16.04 下安装 Nginx
本文首发于个人博客 Cyy’s Blog
转载请注明出处 https://cyyjs.top/blog/5c09c9d2465cda79df33004a
# 安装
安装nginx 执行下面命令
sudo apt-get update
sudo apt-get install nginx
# 服务器配置
/etc/nginx/nginx.conf: Nginx配置文件
可修改配置文件,引入其他配置文件
include /user/config/nginx/*;
如果提示没有权限,可查看 /etc/nginx/nginx.conf中 第一行的user用户配置。
# 常用配置
# 静态站点配置
server {
listen 80;
server_name alibt.top;
root /workspace/app/blog;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
# 反向代理配置
server {
listen 80;
server_name www.alibt.top alibt.top;
location / {
proxy_pass http://127.0.0.1:1234;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
# return 301 https://alibt.top$request_uri;
}
}
# https配置
server {
listen 443;
server_name alibt.top www.alibt.top;
ssl on;
ssl_certificate xxx.pem; # 证书位置
ssl_certificate_key xxx.key; # 私钥位置
ssl_session_timeout 5m;
ssl_ciphers xxx; # 密码加密方式
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # 指定密码为openssl支持的格式
ssl_prefer_server_ciphers on; # 依赖SSLv3和TLSv1协议的服务器密码将优先于客户端密码
location / {
proxy_pass http://127.0.0.1:1234;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
# 常用命令
nginx stop # 暂停
nginx -s reload # 重启
