当我们在一台机器上编译好了Nginx,想把这个编译好的二进制压缩包拷贝部署到其他机器,怎么做?
如果你部署的账号跟你编译的账号一样,同时你部署路径跟你编译路径一样,那么你按照之前的教程就可以部署成功。
但是如果你部署的账号跟你编译的账号不一样,那么需要额外进行配置。
1.新机器非编译账号部署
假定编译安装的目录是/opt/testerzhang
,新部署机器的账号路径是/home/public
- 在你想要部署的目录,解压压缩包
$ tar zxf nginx.tar.gz
$ cd nginx
- 修改配置文件
$ vim conf/nginx.conf
这里列举下需要修改的常规配置
# 由于部署的机器不是按照编译打包的账号来的,所以这里要配置实际部署机器的绝对路径。
error_log /home/public/nginx/logs/error.log;
pid /home/public/nginx/logs/nginx.pid;
http {
...
# 设置访问日志信息
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 /home/public/nginx/logs/access.log main;
client_body_temp_path /home/public/nginx/client_body_temp;
proxy_temp_path /home/public/nginx/proxy_temp;
fastcgi_temp_path /home/public/nginx/fastcgi_temp;
scgi_temp_path /home/public/nginx/scgi_temp;
uwsgi_temp_path /home/public/nginx/uwsgi_temp;
# 隐藏nginx版本
server_tokens off;
# 隐藏后端服务信息
proxy_hide_header Server;
...
# 这里设置端口80的端口配置,并自动重定向到https的网站地址。
server {
listen 80 ;
server_name www.xxx.top;
access_log /home/public/nginx/logs/80.access.log main;
# 限制IP访问,前提对应配置的文件要存在
#include blockip.conf;
return 301 https://www.xxx.top;
}
server {
listen 443 ssl ;
server_name www.qahome.top;
access_log /home/public/nginx/logs/443.access.log main;
# 限制IP访问,前提对应配置的文件要存在
#include blockip.conf;
# 添加同源策略,防止跨站脚本,禁止某些浏览器的内容类型探嗅
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
# SSL证书的配置
ssl_certificate /home/public/zhengshu/1_www.xxx.top_bundle.crt;
ssl_certificate_key /home/public/zhengshu/2_www.xxx.top.key;
ssl_protocols TLSv1.2;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
# 根目录对应的静态文件目录
location / {
root /home/public/website;
index index.html index.htm;
}
# 转发后端请求
#location /backend {
# proxy_set_header Host $host:$proxy_port;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#
# proxy_pass http://10.10.10.10:58080;
#}
...
}
}
2.启停命令
正常在编译后的安装目录,不需要指定配置文件,但是由于是部署新机器,可能不是同一个账号,你需要加上绝对路径的配置文件
- 启动
$ ./nginx -c /home/public/nginx/conf/nginx.conf -e /home/public/nginx/logs/error.log
- 停止
$ ./nginx -c /home/public/nginx/conf/nginx.conf -e /home/public/nginx/logs/error.log -s stop
- 重新加载Nginx配置
$ ./nginx -c /home/public/nginx/conf/nginx.conf -e /home/public/nginx/logs/error.log -s reload
本文没有授权给任何组织、企业和个人转载,未经作者允许禁止转载!
欢迎关注我的公众号testerzhang,原创技术文章第一时间推送。