mac上面启用80端口

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

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

  1. 下载并安装nginx。

    1. Nginx.org网站上下载tar.gz格式的源码包

    2.  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
    3. 在make这一步发生了一个错误,提示:make: *** No rule to make target `build', needed by `default'.  Stop. 这说明在上一步configure有错误。

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

    4. 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的链接ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre

  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

    安装完之后再返回nginx的安装过程中。

   重新执行configure命令,结果发现又有错误:

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.

   还要安装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=/______这个路径指向你的源码安装包路径而不是你安装后的路径!

wtf!

  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,如下图:

143057_ByBu_2393940.png

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

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

144457_OexG_2393940.png

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

145030_k0qe_2393940.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;

151857_yUI2_2393940.png

转载于:https://my.oschina.net/lizhengdong/blog/522655

要在nginx中配置https转发80端口,可以使用以下配置: server { listen 443 ssl; server_name example.com; ssl_certificate /path/to/certificate.crt; ssl_certificate_key /path/to/private.key; location / { proxy_pass http://localhost:80; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; } } 上述配置中,监听443端口并启用SSL,使用的证书和私钥文件需要替换为实际的路径。然后通过设置proxy_pass将请求转发到后端的80端口。同时,需要设置适当的代理头信息,例如Host、X-Real-IP和X-Forwarded-Proto,以便正确地传递客户端的请求。这样配置后,nginx将会对收到的https请求进行转发,将请求发送到后端的80端口上。<span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* [Nginx服务器中配置非80端口的端口转发方法详解](https://download.csdn.net/download/weixin_38655496/14092017)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [Mac中使用Nginx实现80端口转发8080端口](https://download.csdn.net/download/weixin_38703968/12900530)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值