nginx php mysql配置_Ubuntu下nginx+php+mysql配置

本文详细介绍了如何在Linux环境中安装和配置Nginx、PHP-FPM以及MySQL。首先通过`sudo apt-get install nginx`安装Nginx,并配置其启动、停止等操作。接着配置Nginx的http和server块,包括监听端口、SSL设置、日志记录和Gzip压缩。然后安装PHP-FPM和MySQL,并调整php.ini文件以增强安全性。最后,允许远程访问MySQL并确保配置正确。这是一个基础的Web服务搭建教程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Nginx

sudo apt-get install nginx

启动 sudo /etc/init.d/nginx start

{start 启动|stop 停止|restart 重启|reload|force-reload|status|configtest|rotate|upgrade}

配置nginx.conf文件(一般在/etc/nginx/文件夹下)

user www-data;

#worker_processes auto;

worker_processes 4;

pid /run/nginx.pid;

events {

worker_connections 768;

# multi_accept on;

}

http {

##

# Basic Settings

##

sendfile on;

tcp_nopush on;

tcp_nodelay on;

#keepalive_timeout 65;

keepalive_timeout 2;

types_hash_max_size 2048;

# server_tokens off;

# server_names_hash_bucket_size 64;

# server_name_in_redirect off;

include /etc/nginx/mime.types;

default_type application/octet-stream;

##

# SSL Settings

##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE

ssl_prefer_server_ciphers on;

##

# Logging Settings

##

access_log /var/log/nginx/access.log;

error_log /var/log/nginx/error.log;

##

# Gzip Settings

##

gzip on;

gzip_disable "msie6";

# gzip_vary on;

# gzip_proxied any;

# gzip_comp_level 6;

# gzip_buffers 16 8k;

# gzip_http_version 1.1;

# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##

# Virtual Host Configs

##

include /etc/nginx/conf.d/*.conf;

include /etc/nginx/sites-enabled/*;

}

#mail {

# # See sample authentication script at:

# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript

#

# # auth_http localhost/auth.php;

# # pop3_capabilities "TOP" "USER";

# # imap_capabilities "IMAP4rev1" "UIDPLUS";

#

# server {

# listen localhost:110;

# protocol pop3;

# proxy on;

# }

#

# server {

# listen localhost:143;

# protocol imap;

# proxy on;

# }

#}

配置default文件(一般在/etc/nginx/sites-available文件夹下)

##

# You should look at the following URL's in order to grasp a solid understanding

# of Nginx configuration files in order to fully unleash the power of Nginx.

# http://wiki.nginx.org/Pitfalls

# http://wiki.nginx.org/QuickStart

# http://wiki.nginx.org/Configuration

#

# Generally, you will want to move this file somewhere, and start with a clean

# file but keep this around for reference. Or just disable in sites-enabled.

#

# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.

##

# Default server configuration

#

server {

listen 80 default_server;

listen [::]:80 default_server ipv6only=on;

# SSL configuration

#

# listen 443 ssl default_server;

# listen [::]:443 ssl default_server;

#

# Note: You should disable gzip for SSL traffic.

# See: https://bugs.debian.org/773332

#

# Read up on ssl_ciphers to ensure a secure configuration.

# See: https://bugs.debian.org/765782

#

# Self signed certs generated by the ssl-cert package

# Don't use them in a production server!

#

# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP

index index.php index.html index.htm index.nginx-debian.html;

server_name server_domain_name_or_IP;

location / {

# First attempt to serve request as file, then

# as directory, then fall back to displaying a 404.

try_files $uri $uri/ =404;

}

error_page 404 /404.html;

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root /var/www/html;

}

location ~ \.php$ {

try_files $uri =404;

fastcgi_split_path_info ^(.+\.php)(/.+)$;

fastcgi_pass unix:/run/php/php7.0-fpm.sock;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

#location ~ \.php$ {

# include snippets/fastcgi-php.conf;

#

# # With php7.0-cgi alone:

# fastcgi_pass 127.0.0.1:9000;

# # With php7.0-fpm:

# fastcgi_pass unix:/run/php/php7.0-fpm.sock;

#}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

PHP

apt-get install php-fpm php-mysql

启动 sudo /etc/init.d/php7.0-fpm start

{start 启动|stop 停止|restart 重启|reload|force-reload|status|configtest|rotate|upgrade}

配置PHP,修改php.ini文件(在/etc/php5/fpm/下)

761行设置,取消分号;将1改为0

cgi.fix_pathinfo=0

重新加载 php-fpm:

service php-fpm reload

Mysql

sudo apt-get install mysql-server

配置远程访问权限:

查看/etc/mysql/my.cnf找到bind-address才发现配置的是 127.0.0.1(bind-address=127.0.0.1),直接改为bind-address=192.168.0.xxx(本机ip),然 后再查看3306端口打开了,ok,可以正常连接了

文章推荐:http://blog.youkuaiyun.com/wzy_1988/article/details/8175385

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值