在虚拟机上用nginx怎么搭建lnmp
发布网友
发布时间:2022-04-23 19:58
我来回答
共2个回答
热心网友
时间:2022-05-01 09:25
<一、参考>
这里以配置2个站点(2个域名)为例,n 个站点可以相应增加调整,假设:
IP地址: 202.55.1.100
域名1 example1.com 放在 /www/example1
域名2 example2.com 放在 /www/example2
配置 nginx virtual hosting 的基本思路和步骤如下:
把2个站点 example1.com, example2.com 放到 nginx 可以访问的目录 /www/
给每个站点分别创建一个 nginx 配置文件 example1.com.conf,example2.com.conf,
并把配置文件放到 /etc/nginx/vhosts/
然后在 /etc/nginx.conf 里面加一句 include 把步骤2创建的配置文件全部包含进来(用 * 号)
重启 nginx
具体过程
下面是具体的配置过程:
1、在 /etc/nginx 下创建 vhosts 目录
mkdir /etc/nginx/vhosts
2、在 /etc/nginx/vhosts/ 里创建一个名字为 example1.com.conf
的文件,把以下内容拷进去
server {
listen 80;
server_name example1.com www. example1.com;
access_log /www/access_ example1.log main;
location / {
root /www/example1.com;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on
127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/www/example1.com/$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
3、在 /etc/nginx/vhosts/ 里创建一个名字为 example2.com.conf
的文件,把以下内容拷进去
server {
listen 80;
server_name example2.com www. example2.com;
access_log /www/access_ example1.log main;
location / {
root /www/example2.com;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on
127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/www/example2.com/$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
4、打开 /etc/nginix.conf 文件,在相应位置加入 include 把以上2个文件包含进来
user nginx;
worker_processes 1;
# main server error log
error_log /var/log/nginx/error.log ;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
# main server config
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”‘;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name _;
access_log /var/log/nginx/access.log main;
server_name_in_redirect off;
location / {
root /usr/share/nginx/html;
index index.html;
}
}
# 包含所有的虚拟主机的配置文件
include /usr/local/etc/nginx/vhosts/*;
}
5、重启 Nginx
/etc/init.d/nginx restart
</参考>
<二、我的实例>
--------- vhosts/led.conf
server {
listen
80;
server_name
www.led.com
index
index.html index.htm index.php;
root /usr/local/vhost/led;
#charset koi8-r;
#access_log
logs/host.access.log main;
location / {
root /usr/local/vhost/led;
index index.html index.htm
index.php;
}
#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;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#
proxy_pass
http://127.0.0.1;
#}
location ~
.*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/scripts$fastcgi_script_name;
include
fastcgi_params;
}
location ~
.*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
log_format
access '$remote_addr - $remote_user [$time_local] "$request"
'
'$status $body_bytes_sent "$http_referer"
'
'"$http_user_agent"
$http_x_forwarded_for';
}
---------------- nginx.conf
user
nginx nginx;
worker_processes 8;
error_log logs/error.log;
#error_log logs/error.log
notice;
#error_log logs/error.log
info;
pid
/usr/local/nginx/nginx.pid;
worker_rlimit_nofile 65535;
events {
use
epoll;
worker_connections 65535;
}
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;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile
on;
tcp_nopush
on;
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay
on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size
128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain
application/x-javascript text/css application/xml;
gzip_vary
on;
server
{
listen
80;
server_name
_;
server_name_in_redirect off;
location /
{
root
/usr/share/nginx/html;
index
index.html;
}
}
#
包含所有的虚拟主机的配置文件
include
/usr/local/nginx/conf/vhosts/*;
}
热心网友
时间:2022-05-01 10:43
可以下载一个epel的yum源 +通过命令yum install -y nginx mysql mysql-server php
可以通过源码部署
lnmp集成环境用nginx的ssl协议来代理workman的websocket服务_百度...
因此,要在lnmp集成环境中使用nginx的websocket代理服务,首先必须确认你的nginx版本要高于1.3.13版本。对于配置就很简单了,具体的配置如下所示:http { upstream wsbackend { server 127.0.0.1:3000; # websocket服务器后端地址 } server { listen 8080; location / { # 如...
socks5 代理软件 - StormProxies
StormProxies是全球大数据IP资源服务商,其住宅代理网络由真实的家庭住宅IP组成,可为企业或个人提供满足各种场景的代理产品。点击免费测试(注册即送1G流量)StormProxies有哪些优势?1、IP+端口提取形式,不限带宽,IP纯净高匿;2、覆盖全球20...
docker-docker搭建LNMP运行环境-2.nginx
首先,创建一个临时的nginx容器,并进入容器中查看是否有需要的目录。进行测试。在宿主机/docke/www/test/public目录中创建index.html文件。保存并退出,然后通过浏览器访问宿主机IP,就能看到页面。通过浏览器访问,输出正常。
Nginx 实践案例(源码编译安装方式):利用LNMP搭建wordpress站点_百度...
4.1 部署php-fpm服务;4.2 部署Nginx服务。4.2.1 编译安装nginx;4.2.2 配置Nginx支持fastcgi;4.2.3 测试PHP工作是否正常。准备测试页面,测试PHP的ping,查看状态页。5. 部署WordPress。5.1 准备WordPress文件;5.2 初始化WordPress。在浏览器内输入blog.shone.cn。6. 优化WordPress。6.1 允...
如何在CloudFlare下Nginx实现访客真实IP网站日志?
修改lnmp.conf文件,并且升级nginx即可。在lnmp.conf添加–with-http_realip_module,如下。升级nginx 在 http://nginx.org/en/download.html 查看版本,然后输入合适的版本。等待升级完成即可。修改网站的配置文件 /usr/local/nginx/conf/nginx.conf 在server后面的http{}中添加如下内容 重载nginx配置生效...
如何更改lnmp+nginx环境下用WordPress搭建的网站的端口号
特地写上一篇关于LinodeVPS配置LNMP环境和搭建wordpress的文章。其实这篇文章也不会写详细的如何配置lnmp,因为lnmp.org官网本身就有详细的教程和军哥的论坛后援技术支持。这里主要叙述一些我当初实施过程中的思路和心得。
LAMP和LNMP区别是什么
1、架构上:LAMP==Linux+Apache+Mysql+PHP LNMP==Linux+Nginx+Mysql+PHP LAMP是Linux+Apache+Mysql+PHP的组合方式,用的是Linux;LNMP是Linux+Nginx+Mysql+PHP的组合方式,其特点是利用Nginx的快速与轻量级,替代以前的LAMP(Linux+Apache+Mysql+PHP)的方式。由于安装方便,并且安装脚本也随时更新。2、...
oneinstack安装lnmp之后还需要 对nginx与php集成吗
ZendGuardLoader 根据自己需求安装Pureftpd、phpMyAdmin 根据自己需求安装Memcached、Redis 根据自己需求可使用tcmalloc或者jemalloc优化MySQL、Nginx 提供添加虚拟主机脚本 提供Nginx/Tengine、PHP、Redis、phpMyAdmin升级脚本 提供本地备份和远程备份(服务器之间rsync)脚本 提供CentOS 6、7下HHVM安装 ...
LNMP安装了哪些软件?安装目录在哪
LNMP相关配置文件位置 Nginx主配置文件:/usr/local/nginx/conf/nginx.conf /root/vhost.sh添加的虚拟主机配置文件:/usr/local/nginx/conf/vhost/域名.conf MySQL配置文件:/etc/my.cnf PHP配置文件:/usr/local/php/etc/php.ini php-fpm配置文件:/usr/local/php/etc/php-fpm.conf PureFtpd配置...
ECS?Linux?服务器如何配置网站以及绑定域名?
Linux上如果要搭建网站服务,那需要安装配置WEB依懒的运行环境,现在主流的WEB环境有LNMP、或者Tomcat+Java+MySQL系的。考虑到当下LNMP环境居多,所以我们建议先安装LNMP集成环境。Linux下安装LNMP集成环境 LNMP集成环境代表的是:Linux+Nginx+MySQL+PHP的集成安装包,安装方法如下:wgetlnmp/lnmp1.5.tar.gz...
电脑上的LNMP是什么,它的作用是什么。
LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。 Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:debian、centos、ubuntu、fedora、gentoo等。[1] Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。[2] Mysql是一个小型关系...