安装依赖
yum install -y gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
下载安装包
cd /tmp
wget http://nginx.org/download/nginx-1.23.1.tar.gz
解压
sudo tar zxvf /tmp/nginx-1.23.1.tar.gz
配置configure
cd nginx-1.23.1
sudo ./configure
修改makefile文件
sudo vi Makefile
在命令前加上sudo
执行make & make install
make & make install
启动nginx
cd /usr/local/nginx/sbin
sudo ./nginx
sudo /usr/local/nginx/sbin/nginx
查看是否启动
ps aux | grep nginx
ps ef | grep nginx
关闭nginx
killall nginx
/opt/calb_report/dist
vue.config.js中配置 publicPath:
publicPath: '/upload'
设置代理
location /upload/ {
alias /opt/calb_report/dist/;
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass http://10.112.218.173:5005;
}
添加服务
vi /lib/systemd/system/nginx.service
nginx.service内容如下:
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx reload
ExecStop=/usr/local/nginx/sbin/nginx quit
PrivateTmp=true
Restart=always
# Restart service after 5 seconds if the dotnet service crashes:
RestartSec=5
KillSignal=SIGINT
SyslogIdentifier=nginx
User=root
[Install]
WantedBy=multi-user.target
sudo systemctl start nginx.service (启动nginx服务)
sudo systemctl stop nginx.service (停止nginx服务)
sudo systemctl enable nginx.service (设置开机自启动)
sudo systemctl disable nginx.service (停止开机自启动)
sudo systemctl status nginx.service (查看服务当前状态)
sudo systemctl restart nginx.service (重新启动服务)文章来源:https://www.toymoban.com/news/detail-459849.html
sudo systemctl list-units --type=service (查看所有已启动的服务)文章来源地址https://www.toymoban.com/news/detail-459849.html
到了这里,关于centos下安装nginx的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!