小菜鸟入门nginx

实现功能:端口进行转发

比如我实际运行的是·http:localhost:5000 但是我想通过localhost:80 进行访问。

过程

1 下载nginx

2 解压到某个目录(比如我放在C盘根目录)

3 进入目录(C:\nginx-1.14.0)我的是C盘,不同目录不一样。

4 在该目录打开命令行窗口,执行 start nginx or start nginx.exe ,窗口会一闪而过。

5 查看nginx 是否正常运行 :命令行窗口tasklist /fi "imagename eq nginx.exe" 如果正常运行可以看到

如果没有看到运行的进程 进入目录logs,查看文件error.log,查看具体的错误。

我刚开始也遇到了无法运行的错误,错误信息如下:

2018/04/22 20:36:14 [emerg] 10404#316: bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket in a way forbidden by its access permissions)

后来删除IIS默认绑定的default站点,解决问题。

6.编辑文件C:\nginx-1.14.0\conf\nginx.conf

修改其 server节点下的内容:

原内容:

 server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

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

修改后:

 server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass https://localhost:5001;
            # root   html;
            # index  index.html index.htm;
        }

只添加了一行proxy_pass https://localhost:5001,后边的两行注释掉了。

7 重新载入nginx,nginx -s reload

8 访问http://localhost


运行成功。

笔记

命令 解释
nginx -s stop 强制停止
nginx -s quit 正常退出
nginx -s reload 更改配置文件用到的命令,用新的配置文件启动新的进程,然后正常推出旧的进程。
nginx -s reopen 重新打开日志文件。

ubuntu 的nginx 默认配置文件在/etc/nginx/conf.d/default.conf下。

posted @ 2018-04-22 21:24  Bluto  阅读(503)  评论(0编辑  收藏  举报