首先找到nginx的配置文件nginx.conf,打开配置文件后找到类似下面一段:

[root@localhost nginx]# cd /etc/nginx/conf.d/

然后把目录下面的文件都列出来:

[root@localhost conf.d]# ll  

默认的话,目录下面有个default.conf文件

打开default.conf文件后如下:

server {listen       80;server_name  localhost;#charset koi8-r;access_log  /var/log/nginx/access.log  main;root        /var/www/baidu;index       index.php index.html index.htm;location / {try_files $uri $uri/ =404;}error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   /var/www;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000#location ~ \.php($|/) {try_files $uri =404;#rewrite ^/index.php/(.*)$  /$1 last;fastcgi_pass unix:/var/www/php-fpm.sock;fastcgi_index index.php;fastcgi_param PATH_INFO $fastcgi_path_info;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;fastcgi_intercept_errors on;fastcgi_ignore_client_abort off;fastcgi_connect_timeout 60;fastcgi_send_timeout 180;fastcgi_read_timeout 180;fastcgi_buffer_size 128k;fastcgi_buffers 4 256k;fastcgi_busy_buffers_size 256k;fastcgi_temp_file_write_size 256k;}#location ~ \.php$ {#    root           html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}
}

如果把上面的配置作为本地配置一个百度网站的设置,那么其访问的端口为默认80端口,访问地址就是:http://localhost/

如果我们想用81端口配置为本地的另外一个网站的访问入口,应该怎么配置呢?

首先你需要在conf.d目录下创建一个以.conf结尾的文件,比如:google.com.conf文件,或者直接copy一个default.conf文件也可以,具体配置如下:

server {listen       81;server_name  localhost;#charset koi8-r;access_log  /var/log/nginx/access.log  main;root        /var/www/google;index       index.php index.html index.htm;location / {try_files $uri $uri/ =404;}error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   /var/www;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000#location ~ \.php($|/) {try_files $uri =404;#rewrite ^/index.php/(.*)$  /$1 last;fastcgi_pass unix:/var/www/php-fpm.sock;fastcgi_index index.php;fastcgi_param PATH_INFO $fastcgi_path_info;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;fastcgi_intercept_errors on;fastcgi_ignore_client_abort off;fastcgi_connect_timeout 60;fastcgi_send_timeout 180;fastcgi_read_timeout 180;fastcgi_buffer_size 128k;fastcgi_buffers 4 256k;fastcgi_busy_buffers_size 256k;fastcgi_temp_file_write_size 256k;}#location ~ \.php$ {#    root           html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}
}

保存后,重启nginx服务器

访问:http://localhost:81看看是否成功吧。

注意:配置里面的目录文件一定要存在,不然无法启动nginx。

nginx 监听多个端口 80和81相关推荐

  1. nginx 监听非标准端口80,重定向端口丢失问题解决

    nginx 监听非标准端口80,重定向端口丢失问题解决 参考文章: (1)nginx 监听非标准端口80,重定向端口丢失问题解决 (2)https://www.cnblogs.com/qianxunm ...

  2. Nginx监听443端口配置SSL证书

    先去宝塔:https://www.bt.cn/申请一个免费SSL证书: 点支付订单后,还需要再列表 验证域名,验证域名需要在自己的域名解析配置txt类型字符串值如下,解析值在宝塔SSL申请列表详情可以 ...

  3. nginx监听事件流程

    在前面的几篇文章中已经分析了master进程.work进程的初始化流程.但一直没有分析监听socket的创建流程,nginx服务器只有在创建socket, 绑定socet,监听socket执行完成后, ...

  4. php进程监听是什么意思,多进程监听同个端口及单进程监听多个端口的php版本实现...

    最近在看nginx设计原理时思考到两个问题,便是: 多个进程能否监听同个端口? 单个进程能否监听多个端口? 当然随着学习的深入,答案均是肯定的,在这个过程中笔者为了验证,用php写了两个例子,在这里分 ...

  5. 单个进程监听多个端口及多个进程监听同一个端口

    单个进程监听多个端口 单个进程创建多个 socket 绑定不同的端口,TCP, UDP 都行 多个进程监听同一个端口(multiple processes listen on same port) 方 ...

  6. TCP和UDP可以同时监听相同的端口

    TCP和UDP可以同时监听相同的端口吗(可以) IP数据包首部有个叫做协议的字段,指出了上层协议是TCP还是UDP还是其他.操作系统有能力根据接受的报文的IP字段里面的协议部分判断这个报文是什么报文, ...

  7. 本地启动 Hybris 服务器调试模式后,监听在 8000 端口

    使用命令行 hybrisserver.bat debug 启动后,在任务管理器查看 Java.exe 进程: 能看到监听在 8000端口,启用的命令行参数如下: "C:\Program Fi ...

  8. java 监听本地端口_JAVA本地监听与远程端口扫描

    摘 要 随着Internet的不断发展,信息技术已成为社会进步的巨大推动力.不管是存储于服务器里还是流通于Internet上的信息都已成为一个关系事业成败的关键,这就使保证信息的安全变得格外重要.本地 ...

  9. 如何判断目标主机是否在监听一个UDP端口(阿里云二面)

    面试官:我问一个简单的问题,如何判断目标主机是否在监听一个UDP端口port? 我:给目标主机发送一个UDP报文(含目标port),如果收到回复,表示监听,否则表示没有监听. 面试官:有没有通用一点的 ...

  10. Golang net/http包 同时监听多个端口

    背景 在golang中 需要同时监听多个端口 对http请求进行相同的处理(handler) 实现 代码如下 很简单 func handler1(w http.ResponseWriter, r *h ...

最新文章

  1. Squirrel的安装(windows上Phoneix可视化工具)
  2. 《从问题到程序:用Python学编程和计算》——3.4 定义函数
  3. hs_err_pid
  4. mysql -u -p -d_mysqld_exporter监控mysql
  5. 关于错误提示:此实现不是 Windows 平台 FIPS 验证的加密算法的一部分的解决方案...
  6. 使用pandas时遇到ValueError: numpy.dtype has the wrong size, try recompiling
  7. NB-IoT(8)---网络编程
  8. 祁是计算机,南京邮电大学计算机/软件学院导师介绍:祁正华
  9. Hibernate-Criteria
  10. [ZT]ASP.NET中如何防范SQL注入式攻击
  11. 数据结构—树(大纲)
  12. ServletContextListener 启动SPRING加载数据到缓存的应用
  13. 15个网页数据采集中最常遇到的问题(干货)
  14. ​Debug如何引流(降龙十八掌)
  15. ios10--拳皇动画
  16. 数据分析报告2:Superstore销售情况分析
  17. php php_sapi cli,php_sapi_name() cli
  18. 【思维导图怎么画】万彩脑图大师教程 | 添加链接
  19. Python实现网络聊天
  20. lua入门之环境搭建、第一个demo

热门文章

  1. c语言怎么把数字倒过来_如何用C语言将一个数字倒序过来
  2. KL Divergence ——衡量两个概率分布之间的差异
  3. 计算机按电源键无法反应,笔记本无法正常开机,按下电源键无任何反应要过一段时间才可以开机...
  4. PS制作科幻特效的金色立体文字
  5. python gca_Matplotlib入门-3-plt.gca( )挪动坐标轴
  6. 简单的安卓网络音乐视频播放器app
  7. torch.optim.lr_scheduler源码和cosine学习率策略学习
  8. unity怎么制作云飘动_【Unity3D】实现云循环漂浮效果
  9. Mysql主从备份数据库服务器搭建
  10. Re5:读论文 TWAG: A Topic-guided Wikipedia Abstract Generator