首页 > 系统相关 >Nginx配置nginx.conf文件实现一个IP两个域名

Nginx配置nginx.conf文件实现一个IP两个域名

时间:2023-12-07 23:01:45浏览次数:39  
标签:www log Nginx IP nginx html user error

#安装PCRE库支持

yum install pcre-devel pcre -y

#下载Nginx源码包

cd /usr/src

wget -c http://nginx.org/download/nginx-1.12.0.tar.gz 

#解压Nginx源码包

tar -xzf nginx-1.12.0.tar.gz

#进入解压目录,然后sed修改Nginx版本信息为JWS

cd nginx-1.12.0 ; sed -i -e 's/1.12.0//g' -e 's/nginx\//JWS/g' -e

's/"NGINX"/"JWS"/g' src/core/nginx.h

#预编译Nginx

useradd www ;./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

#.configure预编译成功后,执行make命令进行编译

make

#make执行成功后,执行make install 正式安装

make install

#至此Nginx WEB服务器安装完毕。

/usr/local/nginx/sbin/nginx  -t  检查nginx配置文件是否正确

然后启动nginx,/usr/local/nginx/sbin/nginx 回车即可。查看进程是否已启动:

[root@localhost ~]# ps -ef |grep nginx

nobody    5381 30285  0 May16 ?        09:04:31 nginx: worker process         

root     30285     1  0  2017 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx

root     32260 32220  0 12:34 pts/0    00:00:00 grep nginx

[root@localhost ~]#

#中间碰见问题:nginx进程正常但,无法正常打开网页,通过百度修改nginx.conf文件里的user nobody 行,把前面的井号去掉,运行正常。

user nobody格式: user user [group

user : 指定nginx 运行的用户

group: 指定nginx可运行的组

本地浏览器输入linux网卡地址即可访问主页:

welcome to nginx

Nginx配置nginx.conf文件实现一个IP两个域名_html

#相关查询命令:

nginx -s reload 重启服务

nginx -t 检查nginx配置文件是否正常

#配置本地电脑host文件

文件路径:C:\Windows\System32\drivers\etc在host文件的空白处添加个nginx主机的ip和域名对应关系

192.168.88.71 www.fjtest.net

192.168.88.71 www.fjtest2.net

#编辑nginx.conf文件

vim /usr/local/nginx/conf/nginx.conf

user  nobody;

worker_processes  1;

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {

   worker_connections  1024;

}

http {

   include       mime.types;

   default_type  application/octet-stream;

   #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

   #                  '$status $body_bytes_sent "$http_referer" '

   #                  '"$http_user_agent" "$http_x_forwarded_for"';

   #access_log  logs/access.log  main;

   sendfile        on;

   #tcp_nopush     on;

   #keepalive_timeout  0;

   keepalive_timeout  65;

   #gzip  on;

   server {

       listen       80;

       server_name  www.fjtest.net;

       #charset koi8-r;

       #access_log  logs/host.access.log  main;

       location / {

           root   html/fj;

           index  index.html index.htm;

           }

}

   server {

       listen       80;

       server_name  www.fjtest2.net;

       #charset koi8-r;

       #access_log  logs/host.access.log  main;

       location / {

           root   html/fj2;

           index  index.html index.htm;

       }

       #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   html;

       }

#同时创建了html下的两个文件,一个叫fj,一个叫fj2,然后把html下的index.html文件拷贝到对应的文件内。

Nginx配置nginx.conf文件实现一个IP两个域名_nginx_02

ca

#完成后即可通过浏览器分别访问两个域名:www.fjtest.net和www.fjtest.net


标签:www,log,Nginx,IP,nginx,html,user,error
From: https://blog.51cto.com/u_14190462/8728336

相关文章

  • 【愚公系列】2023年12月 面向对象设计原则(四)-依赖倒置原则(Dependence Inversion Pr
    ......
  • pip 安装 mysqlclient报错ERROR: Could not build wheels for mysqlclient, which is
    这是本地环境中没有安装C++的环境,安装好后再次运行报错:国内网站上找了半天,试了又试,不能根本上解决问题,最后从国外的网站上找到的:下载安装MariaDBCConnector,地址:DownloadMariaDBConnectorsfordataaccess&analysis|MariaDB,安装到默认路径下,关闭重新打开cmd,输入:pi......
  • P1084 [NOIP2012 提高组] 疫情控制
    题意:H国有$n$个城市,这\(n\)个城市用$n-1$条双向道路相互连通构成一棵树,$1$号城市是首都,也是树中的根节点。H国的首都爆发了一种危害性极高的传染病。当局为了控制疫情,不让疫情扩散到边境城市(叶子节点所表示的城市),决定动用军队在一些城市建立检查点,使得从首都到边境......
  • 前端学习-JavaScript学习-js基础-API02
    学习视频:黑马程序员视频链接事件监听三要素:事件源、事件类型、事件处理程序随机点名案例<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"&......
  • 【Nginx/IIS】解决uniapp/Vue history模式下页面刷新404
    uniapp/Vue开启History模式本地开发:二级页面刷新或者通过链接进入二级页面是正常的打包部署后:二级页面刷新或者通过链接进入二级页面会报错404页面找不到 解决方案:Nginx配置:在nginx.conf的对应location里配置一行代码try_files$uri$uri//index.html;location/h5{......
  • E. Good Triples
    E.GoodTriplesGivenanon-negativeintegernumber$n$($n\ge0$).Let'ssayatripleofnon-negativeintegers$(a,b,c)$isgoodif$a+b+c=n$,and$digsum(a)+digsum(b)+digsum(c)=digsum(n)$,where$digsum(x)$isthesumofdigitsofn......
  • 支持生成接口文档!Apipost IDEA插件使用体验
    前言Idea是一款功能强大的集成开发环境(IDE),它可以帮助开发人员更加高效地编写、调试和部署软件应用程序,Idea还具有许多插件和扩展,可以根据开发人员的需要进行定制和扩展,从而提高开发效率,今天我们就来介绍一款国产的API调试插件:Apipost-Helper什么是Apipost-Helper?Apipost-He......
  • 无类别域间路由 、无分类域间路由 (CIDR)IP地址简介
    一、原始的IP地址表示方法及其分类(近几年慢慢淘汰)IP地址是由4字节,32位表示的,为了表示方便,通常用点分十进制表示法,例如大家常见的:192.168.0.52,四个字节,通过点进行分隔,看起来十分清晰。IP地址的32位是由网络号+主机号组成的,也就是说这32位中,左边的某些连续位表示网络号,右边的某些连......
  • 阿里巴巴宣布分红 25 亿美元;苹果故意降低 iPhone 性能被判赔偿丨 RTE 开发者日报 Vol.
       开发者朋友们大家好: 这里是「RTE开发者日报」,每天和大家一起看新闻、聊八卦。我们的社区编辑团队会整理分享RTE(RealTimeEngagement)领域内「有话题的新闻」、「有态度的观点」、「有意思的数据」、「有思考的文章」、「有看点的会议」,但内容仅代表......
  • windows 安装mysql 和不能通过ip访问到数据库
     一、确认windows是否已经安装mysql1.按【Win+R】打开运行2.输入【services.msc】打开服务3、在服务列表中查找MySQL,如果有mysql服务则表示Windows已经安装MySQL,如果没有MySQL服务则表示Windows没有安装MySQL二、下载MySQL安装包1、mysql官网下载地址  https://d......