美文网首页
Mac上启用80端口——nginx的安装

Mac上启用80端口——nginx的安装

作者: Melody_YM | 来源:发表于2018-05-31 14:23 被阅读78次

现在mac上有个新需求,需要tomcat使用80端口而不是8080端口。

mac上使用80端口需要root权限,所以不能直接使用。而是需要使用nginx,启动nginx后它可以使用80端口,然后映射到tomcat的8080端口上。

下载并安装nginx。
Nginx.org网站上下载tar.gz格式的源码包。

cd ~/Downloads
tar xvzf nginx-1.9.5.tar.gz 
cd nginx-1.9.5
sudo ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-openssl=/usr/local/openssl
sudo make

在make这一步发生了一个错误,提示:make: *** No rule to make target build', needed bydefault'. Stop. 这说明在上一步configure有错误。

查看configure,发现没有配置prec。

checking for PCRE library ... not found
checking for PCRE library in /usr/local/ ... not found
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found

所以需要提前安装 PCRE库。

    PCRE的链接[https://www.openssl.org/source/openssl-1.0.2l.tar.gz](https://www.openssl.org/source/openssl-1.0.2l.tar.gz)
  sudo tar xvfz pcre-8.36.tar.gz 
  cd pcre-8.36
  sudo ./configure --prefix=/usr/local --enable-utf8 
  sodu make
  sudo make
  sudo make install

还要安装openssl。

tar xvzf openssl-1.0.2a.tar.gz 
   cd openssl-1.0.2a
  ./config --prefix=/usr/local/openssl
  
  在make之前,在openssl-1.0.2a目录下找到Makefile这个文件,用编辑器打开查找,将darwin-i386-cc替换成darwin64-x86_64-cc,保存。
  
  sudo make
  sudo make install
  sudo ln -s /usr/local/openssl/bin/openssl /usr/local/openssl 
  openssl version

openssl安装完毕。

接着返回nginx的configure,结果发现还报错!

原来编译命令也就是 with-openssl=/______这个路径指向你的源码安装包路径而不是你安装后的路径!

  sudo ./configure --prefix=/usr/local/nginx --with-openssl=/Users/lizhengdong/Downloads/openssl-1.0.2a
  make
  sudo make
  sudo make install
  
  加入环境变量
  ~/.bash_profile  (一般在这个文件中添加用户级环境变量)
  添加下面环境变量:
  export PATH=${PATH}:/usr/local/nginx/sbin
  
  nginx -V
nginx version: nginx/1.9.5
built by clang 7.0.0 (clang-700.1.76)
configure arguments: --prefix=/usr/local/nginx --with-openssl=/Users/lizhengdong/Downloads/openssl-1.0.2a

安装完毕,启动nginx试一下,sudo nginx,在浏览器里输入localhost,如下图

image.png

说明nginx没问题,sudo nginx -s stop 关闭nginx。

进入nginx目录/usr/local/nginx,打开nginx.conf。

image.png 改成下图这样。proxy_pass,它表示代理路径,相当于转发。 image.png

修改完成后运行了nginx -s reload进行重新加载配置文件

重启nginx,欧克了!

localhost:8080换成其他url的时候,前面再加一些配置。

 proxy_redirect     off;
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        autoindex off;
```![image.png](https://img.haomeiwen.com/i1442189/7af0355b4fa5dfc2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)











相关文章

  • Mac上启用80端口——nginx的安装

    现在mac上有个新需求,需要tomcat使用80端口而不是8080端口。 mac上使用80端口需要root权限,所...

  • Mac解决Nginx无法使用80端口

    之前在Mac下安装Nginx,默认它会选择8080端口,查了一下说是因为Mac默认占用了80端口,因为不紧急所以就...

  • nginx

    mac 安装 启动 重启 停止找到主进程master process的id杀死主进程 nginx80端口转发其他端...

  • mac 关闭apache httpd 开机启动

    文章转自:风云社区www.scoee.com mac默认安装了apache,随机启动会占用80端口,导致nginx...

  • Nginx 简单的负载/反向代理配置

    安装Nginx nginx默认使用80端口,请确保80未被使用 nginx 负载 新建配置文件blance-tes...

  • Nginx的安装和使用

    事先准备 nginx默认端口也是80,我们安装过了apache,端口也是80,我们主要用nginx,所以我们把ap...

  • 阿里云CentOS部署

    1.安装nginx yum install nginx -y 2.启动nginx nginx 3.开启本地80端口...

  • linux服务器安装nginx

    1:检查80端口是否被占用。2:安装nginx 给nginx配置安装目录,就是nginx存放的目录 我一般安装软件...

  • ubuntu+django+nginx+uwsgi+https环

    1.Nginx安装 sudo apt-get install nginx 如果安装了apache并占用了80端口会...

  • Phabricator安装

    1 .下载phabricator源码 2.安装Nginx 安装后,Nginx应自动启动,检查80端口是否正常 应看...

网友评论

      本文标题:Mac上启用80端口——nginx的安装

      本文链接:https://www.haomeiwen.com/subject/kyyqsftx.html