zoukankan      html  css  js  c++  java
  • Nginx 配置二级域名(Ubuntu)

    此配置 需要先进阿里云官网,再进入 万网里面进行解析域名,再用Nginx命令进行配置,,,如果没有申请端口号,则要先去申请了再进行解析

    一、申请端口号。

    1.进入阿里云=>进入实例=>管理实例=>安全组规则=>右上角 添加安全组规则(寻找一个常用的端口,添加一个即可比如说  88 端口,,添加页面  端口范围填:88/88,授权对象填:0.0.0.0/0)

     

     2.添加完之后 进入万网解析那里,点击解析 ,,然后再添加解析(主机记录填写你要的二级域名,记录值填公网IP),然后就可以了,,主机记录里面不用写.com或啥子www之类的,直接写名字

    二,进入Xshell进行命令语句添加进行配置Nginx

      首先要建一个目录,上传项目的位置

    1.建一个文件夹在www下面,与html同级

    # cd /

    # cd /var/www   =>选择 www文件

    # ll    =>列出www文件夹里面的内容

    # ls

    # mkdir youbao    =>进行添加的文件名字 youbao

    # ls

    现在你可以去查看www下面新增了youbao这个文件夹,然后把项目在上传进去!!!!!!然后进行连接数据库,,,更改项目内数据库的配置,服务器地址为公网IP以及密码,,,然后接下来在进行更改Nginx文件

    # find / -name nginx.conf    => 寻找conf文件

    # vim /etc/nginx/nginx.conf   =>进入conf文件以备修改

    进去之后 要按一下e这个键,(温馨提示:不要按enter键)

    文件server里面写  88为你添加的端口号,server_name 的youbao为你的二级域名,,root里面为为上线项目的文件夹位置,然后保存退出  :wq

    server {
    listen 88;
    server_name youbao.benecess.com;
    charset utf-8;
    #access_log logs/host.access.log main;
    root /var/www/youbao/public;
    index index.html index.htm index.php;
    location / {
    if (!-e $request_filename) {
    rewrite ^(.*)$ /index.php?s=$1 last;
    break;
    }
    }
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
    }
    location ~ .php$ {
    fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    set $real_script_name $fastcgi_script_name;
    if ($fastcgi_script_name ~ "^(.+?.php)(/.+)$") {
    set $real_script_name $1;
    set $path_info $2;
    }
    fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
    fastcgi_param SCRIPT_NAME $real_script_name;
    fastcgi_param PATH_INFO $path_info;
    }
    location ~ .*.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
    expires 30d;
    access_log off;
    }
    location ~ .*.(js|css)?$ {
    expires 7d;
    access_log off;
    }
    }

     

    2.然后去寻找conf

    # find / -name tourism.benecess.com.conf

    # cd tourism.benecess.com.conf youbao.benecess.com.conf

    # cd /usr/local/nginx/conf/vhost

    # cp tourism.benecess.com.conf youbao.benecess.com.conf    =>  cp 为复制

    # vim youbao.benecess.com.conf   =>进去把东西都改成你自己的  比如说域名 文件夹位置

    server {
    listen 80;
    server_name tourism.benecess.com;
    access_log /data/wwwlogs/tourism.benecess.com_nginx.log combined;
    index index.html index.htm index.php;
    root /var/www/html/public;
    if ($host != tourism.benecess.com) { return 301 $scheme://tourism.benecess.com$request_uri; }
    include /usr/local/nginx/conf/rewrite/none.conf;
    #error_page 404 /404.html;
    #error_page 502 /502.html;

    server {
    listen 80;
    server_name tourism.benecess.com;
    access_log /data/wwwlogs/tourism.benecess.com_nginx.log combined;
    index index.html index.htm index.php;
    root /var/www/html/public;
    if ($host != tourism.benecess.com) { return 301 $scheme://tourism.benecess.com$request_uri; }
    include /usr/local/nginx/conf/rewrite/none.conf;
    #error_page 404 /404.html;
    #error_page 502 /502.html;

    location / {
    root /var/www/html/public;
    index index.html index.php;
    if ( -f $request_filename) {
    break;
    }
    if ( !-e $request_filename) {
    rewrite ^(.*)$ /index.php/$1 last;
    break;
    }
    }

    # service nginx restart   => 重启Nginx

     然后就可以直接访问了!!!大功告成

    如果页面报这个错

     则是此项目没有权限的问题(  chmod  千万别写错了哦   )

    # chmod -R 777 /var/www/youbao/runtime

    给了权限之后 就可以应用了,,,,给自己点个赞!!!希望能帮到大家,若有错误请评论..........

  • 相关阅读:
    小木虫等论坛自动签到程序发布
    第一篇随笔
    工作和兴趣哪个更重要?
    weblogic 启动时 报错
    C#动态调用webservice (转载)
    U盘加载,卸载,拔出,插入(转载)
    Simple zip archive unzipper(转载)
    Best C# Blogs(强烈推荐)
    数据无法导入ArcSDE
    Oracle10.2.0.1.0升级Oracle10.2.0.2.0补丁安装指南(转载)
  • 原文地址:https://www.cnblogs.com/dennyxiao/p/8946392.html
Copyright © 2011-2022 走看看