拙网论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 183|回复: 0

Ubuntu18.04 Nginx 配置

[复制链接]

949

主题

1001

帖子

3736

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3736
发表于 2019-12-16 23:34:52 | 显示全部楼层 |阅读模式

https://www.jianshu.com/p/20157e8a0b06

安装环境及版本:
  • 系统:ubuntu 18.04 LTS
  • Nginx: 1.16.0
一  安装
  • 更新软件源
sudo apt update
  • 安装
sudo apt install nginx
  • 命令启动、停止、重启
service  nginx start|stop|reload
  • 外网访问
    默认端口80




    image.png


二  代理转发
  • 配置
sudo vi /etc/nginx/nginx.conf
  • 配置代理
http {    include       mime.types;    default_type  application/octet-stream;    sendfile        on;    keepalive_timeout  65;    server {        #监听端口        listen       80;        #监听地址        server_name  localhost;        location / {            proxy_pass  http://localhost:8081;        }        location /jian {            proxy_pass  https://www.jianshu.com/;        }    }}
代理说明:
访问 http://localhost:80   实际是:https://localhost:8081
访问 http://localhost/jian  实际是:https://www.jianshu.com
location正则写法:
  • 已=开头表示精确匹配
  • ^~ 开头表示uri以某个常规字符串开头,不是正则匹配
  • ~ 开头表示区分大小写的正则匹配;
  • ~* 开头表示不区分大小写的正则匹配
  • / 通用匹配, 如果没有其它匹配,任何请求都会匹配到
location正则详解:https://segmentfault.com/a/1190000002797606
2 重启nginx服务
访问 http://localhost/jian




image.png


三  卸载首先停止nginx 服务
  • 删除nginx
apt --purge remove nginx
  • 自动移除全部不使用的软件包
apt autoremove
  • 列出与nginx相关的软件 并删除显示的软件
dpkg --get-selections|grep nginxapt-get --purge remove nginx


0人点赞



Ubuntu







作者:Lrxc
链接:https://www.jianshu.com/p/20157e8a0b06
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|抱朴守拙BBS

GMT+8, 2025-5-26 02:16 , Processed in 0.214383 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表