博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Ubuntu安装Nginx
阅读量:1984 次
发布时间:2019-04-27

本文共 1846 字,大约阅读时间需要 6 分钟。

其实其他Linux安装都是差不多的 可能稍微目录不一样

 

需要注意的是要改Apache为另外的端口例如81  不然跑2个80会打架的。

 

1.安装nginx

运行:

sudo apt-get intsall nginx

 

2.启动nginx

运行:

sudo /etc/init.d/nginx start

 

3.查看网页

浏览器里输入

提示  Welcome to nginx说明安装成功了!

 

提示:在ubuntu11.04中nginx 默认网站目录为

/usr/share/nginx/www

 

 

这个是被我改了HTML的。

 

不要高兴的太早,要想支持PHP还要经历一番折腾。

 

4.安装PHP5

apt-get install php5-fpm
PHP – FPM是一个守护进程(与初始化脚本 / etc/init.d/php5-fpm )运行FastCGI服务器上的端口 9000 。

5.nginx的配置
配置文件/etc/nginx/nginx.conf
vi /etc/nginx/nginx.conf
你可以通过和网址了解更多配置信息。
增加工作进程,可选,可以不修改
worker_processes 5;
keepalive_timeout 2;
默认虚拟主机配置文件地址/etc/nginx/sites-available/default

CODE:
vi /etc/nginx/sites-available/default
server {
listen 80; ## listen for ipv4; this line is default and implied
listen [::]:80 default ipv6only=on; ## listen for ipv6
root /usr/share/nginx/www;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.html;
}
location /doc {
root /usr/share;
autoindex on;
allow 127.0.0.1;
deny all;
}
location /images {
root /usr/share;
autoindex off;
}
#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 /usr/share/nginx/www;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ /.php$ {
# proxy_pass [url]http://127.0.0.1[/url];
#}
# 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;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache’s document root
# concurs with nginx’s one
#
location ~ //.ht {
deny all;
}
}

 

 6.重启命令

ngnix重新加载一下配置

nginx -s reload
最后重启生效
sudo /etc/init.d/nginx restart
sudo /etc/init.d/php5-fpm restart

转载地址:http://jpwvf.baihongyu.com/

你可能感兴趣的文章
Windows 10安装uWSGI:不可行、失败了
查看>>
Niagara AX之在Station下显示Home节点
查看>>
从Runoob的Django教程学到的
查看>>
控制点:ControlPoint
查看>>
Flask:初见
查看>>
Java Web 1-开发环境搭建(未完待续)
查看>>
Flask: Quickstart解读
查看>>
170406回顾-SQL Server的smalldatetime类型比较
查看>>
Flask:静态文件&模板(0.1)
查看>>
Python解决八皇后问题的代码【解读】
查看>>
Flask:cookie 和 session (0.1)
查看>>
部分编程语言的第一次发布时间及开发者
查看>>
Flask:abort()函数
查看>>
深圳租房之我的经历(验)
查看>>
Flask:redirect()函数
查看>>
美国部分科技公司创始及IPO信息
查看>>
Flask:操作SQLite3(0.1)
查看>>
华夏部分互联网科技公司创始及IPO信息
查看>>
Python开发环境(1):Eclipse+PyDev插件
查看>>
Django 2.0.3安装-压缩包方式
查看>>