如何使用LNMP发布网站或应用?
LNMP新增网站非常容易,在新增网站之前请提前考虑如下三个可能的选项:
PHP版本选择
安装一个网站or安装多个网站
是否需要配置域名(国内网站没有备案的域名无法使用)
场景一:服务器只安装一个网站
当前镜像的网站默认目录是/data/wwwroot/default,如果您打算此服务器上只部署一个网站或应用,建议采用此方式:
通过SFTP工具,将网站源文件上传到此目录/data/wwwroot/default
修改default文件夹的权限和用户组(参考:如何修改Linux文件系统的权限?)
如果没有可用域名,请直接通过http://公网ip 的方式来访问应用
如果有可用的域名,请完成《域名配置》后通过http://域名 的方式来访问应用
场景二:服务器部署多个网站(无域名)
无域名情况下,以部署两个网站为例,具体操作如下:
通过SFTP将第一个网站目录上传到/data/wwwroot/default/目录下面,假设应用程序目录命为“mysite1”
通过Putty工具修改用户权限,运行如下一条命令即可:
~# chown -R nginx.nginx /data/wwwroot/default/mysite1
给mysite1增加一个别名配置文件:通过SFTP打开 /etc/nginx/conf.d/ext/目录,在此目录下新增一个conf文件,假设名称为site1.conf,将下面内容拷贝到文件中,根据你的实际情况进行修改、保存。
location /9panel { alias /data/wwwroot/default/mysite1; index index.php index.html; location ~ ^/9panel/.+\.php$ { alias /data/wwwroot/9panel; fastcgi_pass unix:/dev/shm/php-fpm-default.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /data/wwwroot/$fastcgi_script_name; include fastcgi_params; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp3|wma)$ { expires 30d; } location ~ .*\.(js|css)$ { expires 12h; } location ~* /templates(/.*)\.(bak|html|htm|ini|old|php|tpl)$ { allow 127.0.0.1; deny all; } location ~* \.(ftpquota|htaccess|htpasswd|asp|aspx|jsp|asa|mdb)?$ { deny all; } }
通过Putty工具重启http服务
[root@iZm5ejevtfomfw3dfdf6jmr078Z ~]# systemctl restart nginx [root@iZm5ejevtfomfw3dfdf6jmr078Z ~]# systemctl restart php-fpm
通过http://ip/mysite1 的方式来访问应用,即可进入安装向导
如果在安装向导过程中提示数据库无法自动创建,需要通过http://ip/phpmyadmin 创建数据库
安装第二个网站,操作步骤同样
场景三:服务器部署多个网站(共用一个域名)
共用一个域名情况下,以第一个网站为例,具体操作如下:
将域名解析到服务器IP地址,确保http://域名/能够访问服务器引导页面
通过SFTP将第一个网站目录上传到/data/wwwroot/default/目录下面,假设应用程序目录命为“mysite1”
通过Putty工具修改用户权限,运行如下一条命令即可:
~# chown -R nginx.nginx /data/wwwroot/default/mysite1
给mysite1增加一个别名配置文件:通过SFTP打开 /etc/nginx/conf.d/ext/目录,在此目录下新增一个conf文件,假设名称为site1.conf,将下面内容拷贝到文件中,根据你的实际情况进行修改、保存。
location /9panel { alias /data/wwwroot/default/mysite1; index index.php index.html; location ~ ^/9panel/.+\.php$ { alias /data/wwwroot/9panel; fastcgi_pass unix:/dev/shm/php-fpm-default.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /data/wwwroot/$fastcgi_script_name; include fastcgi_params; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp3|wma)$ { expires 30d; } location ~ .*\.(js|css)$ { expires 12h; } location ~* /templates(/.*)\.(bak|html|htm|ini|old|php|tpl)$ { allow 127.0.0.1; deny all; } location ~* \.(ftpquota|htaccess|htpasswd|asp|aspx|jsp|asa|mdb)?$ { deny all; } }
通过Putty工具重启http服务
[root@iZm5ejevtfomfw3dfdf6jmr078Z ~]# systemctl restart nginx [root@iZm5ejevtfomfw3dfdf6jmr078Z ~]# systemctl restart php-fpm
通过http://域名/mysite1 的方式来访问应用,即可进入安装向导
如果在安装向导过程中提示数据库无法自动创建,需要通过http://ip/phpmyadmin 创建数据库
安装第二个网站,操作步骤同样
场景四:服务器部署多个网站(多个域名)
多个域名情况下,以部署其中一个网站为例,具体操作如下:
将域名解析到服务器IP地址,确保http://域名/能够访问服务器引导页面
通过SFTP将第一个网站目录上传到/data/wwwroot/default/目录下面,假设应用程序目录命为“mysite1”
通过Putty工具修改用户权限,运行如下一条命令即可:
~# chown -R nginx.nginx /data/wwwroot/default/mysite1
给mysite1增加一个域名配置文件:通过SFTP打开 /etc/nginx/conf.d目录,在此目录下新增一个conf文件,假设名称为site1domain.conf,将下面内容拷贝到文件中,根据你的实际情况进行修改、保存。
server { listen 80; server_name site1domain.com www.site1domain.com; index index.html index.htm index.php; charset utf-8; root /data/wwwroot/default/mysite1; access_log /var/log/nginx/default-access.log main; error_log /var/log/nginx/default-error.log crit; location ~ .*\.php$ { fastcgi_pass unix:/dev/shm/php-fpm-default.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /data/wwwroot/default$fastcgi_script_name; include fastcgi_params; try_files $uri = 404; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp3|wma)$ { expires 30d; } location ~ .*\.(js|css)$ { expires 12h; } location ~* /templates(/.*)\.(bak|html|htm|ini|old|php|tpl)$ { allow 127.0.0.1; deny all; } location ~* \.(ftpquota|htaccess|htpasswd|asp|aspx|jsp|asa|mdb)?$ { deny all; } include /etc/nginx/conf.d/ext/*; }
通过Putty工具重启http服务
[root@iZm5ejevtfomfw3dfdf6jmr078Z ~]# systemctl restart nginx [root@iZm5ejevtfomfw3dfdf6jmr078Z ~]# systemctl restart php-fpm
通过http://域名/mysite1 的方式来访问应用,即可进入安装向导
如果在安装向导过程中提示数据库无法自动创建,需要通过http://ip/phpmyadmin 创建数据库
安装第二个网站,操作步骤同样
Last updated