虚拟机LNMP操作记录(三)

nginx配置多站点之端口访问:

查看nginx.conf文件

lnmp 已经默认添加了引入vhost下所有文件的准备: 

 复制server里面的内容:

server
    {
        listen 80 default_server reuseport;
        #listen [::]:80 default_server ipv6only=on;
        server_name _;
        index index.html index.htm index.php;
        root  /home/wwwroot/;

        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        include enable-php.conf;

        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/access.log;
    }

做一些更改:

server
    {
        #端口号
        listen 8888; 
        #域名
        server_name _;
        index index.html index.htm index.php;
        # nginx访问的目录
        root  /home/wwwroot/location-8888; 

        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        # location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        include enable-php.conf; 
        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }
        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }
        location ~ /.well-known {
            allow all;
        }
        location ~ /\.
        {
            deny all;
        }
        access_log  /home/wwwlogs/location-8888.log;
        error_log   /home/wwwlogs/location-8888_error.log;
    }

创建conf文件 并写入新的server:

vim location-8888.conf

重启nginx -- 创建目录 -- 以及访问文件:

 

 并写入内容:

访问: 

如果是访问项目的话

# 这个路径改到项目的public下面

root  /home/wwwroot/location-8888; 

# 增加两段配置如下

location ~ \.php(.*)$ {
      fastcgi_pass   127.0.0.1:9000;
      fastcgi_index  index.php;

      #下面两句是给fastcgi权限,可以支持 ?s=/module/controller/action的url访问模式
      fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

      #下面两句才能真正支持 index.php/index/index/index的pathinfo模式
      fastcgi_param  PATH_INFO  $fastcgi_path_info;
      fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
      include        fastcgi_params;
}

location / {
      index  index.html index.htm index.php;
      #autoindex  on;

      # 伪静态 
      if (!-e $request_filename) {
           rewrite  ^(.*)$  /index.php?s=/$1  last;
           break;
      }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

山山河川

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值