Mac安装Nginx服务器与外网访问

最新

1、安装

brew install nginx
等......

完成后出现 

Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/nginx-1.15.7.mojave.bottle.
Already downloaded: /Users/zhangrongwu/Library/Caches/Homebrew/downloads/5eb4060acd05dd6c3070520418ec02300fe7c929e44c77ef43566d170f2f343c--nginx-1.15.7.mojave.bottle.tar.gz
==> Pouring nginx-1.15.7.mojave.bottle.tar.gz
==> Caveats
Docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

nginx will load all files in /usr/local/etc/nginx/servers/.

To have launchd start nginx now and restart at login:
  brew services start nginx
Or, if you don't want/need a background service you can just run:
  nginx
==> Summary
?  /usr/local/Cellar/nginx/1.15.7: 23 files, 1.4MB

2、启动

sudo nginx

原来就有nginx 并且启动失败

卸载
brew uninstall nginx
删除文件
/usr/local/etc/nginx 目录
/usr/local/var/www 代码目录

然后重复1、2步骤,再打开页面http://localhost:8080/

配置外网地址到Nginx中

ifconfig
查看到自己的ip地址   一般是inet之后的如:
inet 10.4.110.xx netmask 0xfffffc00 broadcast 10.4.111.255

修改配置文件(nginx.conf)中的内容

/usr/local/etc/nginx/nginx.conf

http

 server {
        listen       8000;
        listen       10.4.110.69:8080;
        server_name  10.4.110.69:8080;

        location / {
            root   html;
            index  index.html index.htm;
        }
    }

https,我也没配置过

    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

测试:

浏览器中输入,查看是否能访问默认页面了
http://10.4.110.69:8080

最后

替换自己开发的前端页面为默认页面

/usr/local/var/www
在该目录下替换自己的文件包,层级自己控制
然后进行外网测试
http://10.4.110.69:8080/webapp/app/index.html#/login

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券