美文网首页
Mac安装Nginx服务器与外网访问

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

作者: 程序员不务正业 | 来源:发表于2018-12-21 15:34 被阅读15次

最新

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

相关文章

网友评论

      本文标题:Mac安装Nginx服务器与外网访问

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