在lnmp环境下配置网站

编程入门 行业动态 更新时间:2024-10-15 12:34:45

在lnmp<a href=https://www.elefans.com/category/jswz/34/1771403.html style=环境下配置网站"/>

在lnmp环境下配置网站

安装环境:centos7

安装目录:/www/server

nginx:/www/server/nginx

mysql:/www/server/mysql5.7

php:/www/server/php/5.4.16

网站存放目录:/www/wwwroot

一、安装环境

1、nginx安装

linux下安装nginx_开心lulu的博客-CSDN博客

2、mysql安装

在centos7下安装mysql5.7_开心lulu的博客-CSDN博客

3、php安装

linux下安装php详解(有图)_开心lulu的博客-CSDN博客

二、配置

1、安装完nginx,配置文件nginx.conf默认放在/www/server/nginx/conf/这个目录下。

我准备将它放在nginx的根目录下,具体操作如下:(也可以不移动路径,如果不移动,则这一步省略)

#将nginx.conf移动到nginx根目录下
mv /www/server/nginx/conf/nginx.conf /www/server/nginx/nginx.conf
#创建软链接到原来的目录
ln -s /www/server/nginx/nginx.conf /www/server/nginx/conf
#重新加载配置文件
/www/server/nginx/sbin/nginx -s reload

2、修改配置文件

#定位到nginx根目录
cd /www/server/nginx
#打开nginx.conf
vi nginx.conf

修改后的配置文件内容如下:

user  nginx;
worker_processes  auto;error_log  /www/server/nginx/logs/error.log warn;
pid        /www/server/nginx/logs/nginx.pid;events {worker_connections  1024;
}http {include      /www/server/nginx/conf/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  1800;gzip  on;include /www/server/nginx/webconf/*.conf;
}

注意最后一行:

include /www/server/nginx/webconf/*.conf;

表示将webconf下面的所有conf文件包含进来。

这样,我们的网站配置文件,就可以存放在webconf这个目录

现在,我们以www.xxx网站为例。

先将域名xxx解析到这个服务器的IP

然后,我们在webconf目录中,创建一个xxx.conf的文件

#定位到webconf文件夹
cd /www/server/nginx/webconf
#创建xxx.conf文件
vi xxx.conf

xxx.conf文件的内容如下:

server {listen 80;server_name www.xxx xxx;root /www/wwwroot/xxx;location ~ .*\.(php|php5)?${fastcgi_intercept_errors on;#try_files $uri =404;#fastcgi_pass  unix:/tmp/php-cgi.sock;fastcgi_pass 127.0.0.1:9000;fastcgi_index  index.php;fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;include        fastcgi_params;}location / { if (!-e $request_filename) {rewrite  ^(.*)$  /index.php?s=$1  last;break;}}	location /status {#stub_status on;access_log   off;}location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)${expires      30d;}location ~ .*\.(js|css)?${expires      12h;}
}

保存,OK,配置完成!

重新加载nginx

/www/server/nginx/sbin/nginx -s reload

现在,我们去网站目录/www/wwwroot下创建网站目录

#定位到网站根目录
cd /www/wwwroot
#创建xxx的网站目录
mkdir xxx
#创建一个php文件1.php
vi xxx/1.php

输入如下代码:

<?php
phpinfo();
?>

浏览器中输入网址:.php

好了,网站配置成功,我们可以进行网站开发了,撒花!

更多推荐

在lnmp环境下配置网站

本文发布于:2024-02-27 10:47:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1706248.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:环境   网站   lnmp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!