linux(麒麟系统)安装nginx
1、apt-get安装nginx
安装命令:
sudo apt-get install nginx
2、查看是否安装成功
nginx -v
3、启动nainx
service nginx start
4、重启
service nginx restart
5、停止
service nginx stop
6、启动后,在网页重输入ip地址,即可看到nginx的欢迎页面。至此nginx安装成功
http://localhost/
7、nginx文件安装完成之后的文件位置:
/usr/sbin/nginx:主程序
/etc/nginx:存放配置文件
/usr/share/nginx:存放静态文件
/var/log/nginx:存放日志
8、修改配置文件:
进入 /etc/nginx 执行 sudo vim nginx.conf
修改配置文件后重新加载配置文件 nginx -s reload
a、可以参考下面的配置:

worker_processes auto; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; gzip on; gzip_min_length 5k; gzip_buffers 4 16k; gzip_comp_level 8; gzip_types text/css/woff application/javascript; sendfile on; #tcp_nopush on; keepalive_timeout 600; #gzip on; client_max_body_size 20m; server { listen 8459; server_name localhost; location / { root /data/www/qianduan; index index.html index.htm; try_files $uri $uri/ /index.html; } location /api/ { proxy_pass http://localhost:8458/; #后台API地址 } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { listen 8458; server_name api接口; #允许跨域 add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' '*'; add_header 'Access-Control-Allow-Headers' '*'; location / { proxy_pass http://127.0.0.1:9291; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } }
b、也可以将各server节点,单独创建一个.conf文件,放在/etc/nginx/conf.d目录,然后在nginx.conf通过以下句子引入
新建文件命令
sudo touch web.conf
编辑文件输入以下命令,按i,编辑完后按esc然后:wq退出
sudo vim web.conf
站点内容
server { listen 9898; server_name localhost; location / { root /data/www/qianduan; index index.html index.htm; try_files $uri $uri/ /index.html; } location /api/ { proxy_pass http://localhost:8458/; #后台API地址 } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
http { include mime.types; default_type application/octet-stream; gzip on; gzip_min_length 5k; gzip_buffers 4 16k; gzip_comp_level 8; gzip_types text/css application/javascript; sendfile on; #tcp_nopush on; keepalive_timeout 600; #gzip on; client_max_body_size 20m; include /etc/nginx/conf.d/*.conf; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!