linux安装nginx
linux安装nginx
一、安装依赖包
//一键安装上面四个依赖
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
二、下载并解压安装包
//创建一个文件夹
cd /usr/local
mkdir nginx
cd nginx
//下载tar包
wget http://nginx.org/download/nginx-1.13.7.tar.gz
tar -xvf nginx-1.13.7.tar.gz
以上链接如果不能下载,请从这里下载:
下载下来使用xftp工具上传到以上文件夹中
链接: | https://pan.baidu.com/s/1VApa-1tkoz3RHB8cYjCmng |
---|---|
密码: | 09x1 |
三、安装nginx
//进入nginx目录
cd /usr/local/nginx
//进入目录
cd nginx-1.13.7
//执行命令 考虑到后续安装ssl证书 添加两个模块
./configure --with-http_stub_status_module --with-http_ssl_module
//执行make命令
make
//执行make install命令
make install
四、启动nginx服务(需要在linux系统上开启相应端口)
linux端口相关命令:
查看防火墙状态:firewall-cmd --state
开启防火墙:systemctl start firewalld.service
关闭防火墙:systemctl stop firewalld.service
重启防火墙:systemctl restart firewalld.service
加载防火墙开放端口:firewall-cmd --reload
查看防火墙开放端口列表:firewall-cmd --list-port
开放端口:firewall-cmd --permanent --zone=public --add-port=5672/tcp
关闭端口:firewall-cmd --permanent --zone=public --remove-port=5672/tcp
启动nginx命令:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
五、配置nginx.conf
## 具体配置:比如监听80端口、监听443端口、配置ssl证书等
# 打开配置文件
vi /usr/local/nginx/conf/nginx.conf
配置如下:
server {
listen 443 ssl;
server_name shop.yhrhome.com;
ssl_certificate /usr/local/nginx/cert/shop.yhrhome.com_bundle.crt;
ssl_certificate_key /usr/local/nginx/cert/shop.yhrhome.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
#请按照以下协议配置
ssl_protocols TLSv1.2 TLSv1.3;
#请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_prefer_server_ciphers on;
location / {
root /usr/local/distFiles/dist;
index index.html index.htm;
}
#网关映射 不要用127.0.0.1
location /gw {
# 网关实际访问地址
proxy_pass http://shop.yhrhome.com:8081/gateway/gw;
proxy_set_header host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /yuhang/ {
# 网关实际访问地址(二开服务地址)
proxy_pass http://shop.yhrhome.com:8081/;
proxy_set_header host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#图片映射
location /pic {
# 移动端图片都放在laike-app模块里面
proxy_pass http://shop.yhrhome.com:8081/app;
proxy_set_header host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#图片分享
location /app {
proxy_pass http://shop.yhrhome.com:8081/app;
proxy_set_header host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#微信回调v2
location /wx_notify {
proxy_pass http://shop.yhrhome.com:8081/payment/v2/weChatNotify;
proxy_set_header host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#转发二开接口
location /auctions {
proxy_pass http://shop.yhrhome.com:8081/auctions;
proxy_set_header host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
六、具体使用命令:
进入安装目录中:
cd /usr/local/nginx/sbin
启动:
./nginx
关闭:
./nginx -s stop
重启:
./nginx -s reload
查看进程:
ps -ef | grep nginx
杀死进程:
kill -9 id(进程号)
OK~
本文来自博客园,作者:青喺半掩眉砂,转载请注明原文链接:https://www.cnblogs.com/xiaoguo-java/p/17211137.html