linux配置nginx

nginx官网 下载

#最好选择稳定版本
http://nginx.org/en/download.html

1647480098471

安装过程

#安装依赖
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
#解压文件
tar -zxvf nginx-1.20.2.tar.gz
#配置configure --prefix 代表安装的路径,--with-http_ssl_module 安装ssl,--with-http_stub_status_module查看nginx的客户端状态
./configure --prefix=/usr/local/nginx-1.20.2 --with-http_ssl_module --with-http_stub_status_module
#编译安装nginx
make & make install
#执行成功后在/usr/local目录下会有nginx-1.20.2目录文件
#在cd /usr/local/nginx-1.20.2/sbin目录下执行
./nginx #启动nginx

常用命令

./nginx -t # 验证配置文件是否能正常启动
./nginx #启动nginx
./nginx -s quit #正常停止
./nginx -s stop #快速停止
./nginx -s reload #重新加载
./nginx -V #查看版本信息

配置实例

server {
listen 39001;
# gzip config
gzip on;
gzip_min_length 1k;
gzip_comp_level 9;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
root /usr/share/nginx/html;
location / {
root html;
index index.html index.htm;
# 用于配合 browserHistory使用
try_files $uri $uri/ /index.html;
# 如果有资源,建议使用 https + http2,配合按需加载可以获得更好的体验
# rewrite ^/(.*)$ https://preview.pro.ant.design/$1 permanent;javascript:;
}
location /api {
# proxy_pass http://127.0.0.1:3999; 后台服务地址
proxy_pass http://127.0.0.1:3999/api;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
}
}
posted @   暗夜苹果  阅读(329)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示