nextcloud with nginx install on Archlinux

Archlinux

Modules Install

$ yaourt -S nginx-mainline php-fpm php-gd php-intl php-mcrypt php-apcu nextcloud mariadb syslog-ng

Modules Setup

SYSLOG

$ systemctl enable syslog-ng

$ systemctl restart syslog-ng

PHP

/etc/php/php.ini

date.timezone = Asia/Shanghai

display_errors=On

extension=gd.so

extension=iconv.so

extension=intl.so

extension=mcrypt.so

extension=mysqli.so

zend_extension=opcache.so

extension=pdo_mysql.so

extension=zip.so

[opcache]

opcache.enable=1

opcache.enable_cli=1

/etc/php/conf.d/apcu.ini

extension=apcu.so

[apc]

apc.enable=1

apc.shm_size=32M

apc.ttl=7200

apc.enable_cli=1

MariaDB

$ mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

$ systemctl enable mariadb

$ systemctl restart mariadb

$ mysql_secure_installation

Nginx

TLS/SSL

$ mkdir /etc/nginx/ssl

$ cd /etc/nginx/ssl

$ openssl req -new -x509 -nodes -newkey rsa:4096 $ -keyout server.key -out server.crt -days 1095

$ chmod 400 server.key

$ chmod 444 server.crt

PHP-FPM

/etc/php/php-fpm.d/www.conf

env[PATH] = /usr/local/bin:/usr/bin:/bin

$ systemctl enable php-fpm

$ systemctl restart php-fpm

NextCloud

Init DB

  1. $ mysql -u root -p
  2. mysql> CREATE DATABASE `nextcloud` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
  3. mysql> CREATE USER `nextcloud`@'localhost' IDENTIFIED BY 'xxxxx';
  4. mysql> GRANT ALL PRIVILEGES ON `nextcloud`.* TO `nextcloud`@`localhost`;
  5. mysql> \q

Nginx

$ mkdir /etc/nginx/conf.d/

$ touch /etc/nginx/conf.d/nextcloud.conf

/etc/nginx/nginx.conf

  1. http {
  2. include conf.d/*.conf
  3. ...
  4. }

/etc/nginx/conf.d/nextcloud.conf

  1. upstream php-handler {
  2. #server 127.0.0.1:9000;
  3. server unix:/var/run/php-fpm/php-fpm.sock;
  4. }

  5. #server {
  6. # listen 80;
  7. # server_name 45.63.49.131;
  8. # # enforce https
  9. # return 301 https://$server_name$request_uri;
  10. #}

  11. server {
  12. listen 8080;
  13. listen 443 ssl http2;
  14. ssl on;
  15. server_name 45.63.49.131;

  16. ssl_certificate ssl/server.crt;
  17. ssl_certificate_key ssl/server.key;

  18. # Add headers to serve security related headers
  19. # Before enabling Strict-Transport-Security headers please read into this
  20. # topic first.
  21. add_header Strict-Transport-Security "max-age=15768000;
  22. includeSubDomains; preload;";
  23. add_header X-Content-Type-Options nosniff;
  24. add_header X-Frame-Options "SAMEORIGIN";
  25. add_header X-XSS-Protection "1; mode=block";
  26. add_header X-Robots-Tag none;
  27. add_header X-Download-Options noopen;
  28. add_header X-Permitted-Cross-Domain-Policies none;

  29. # Path to the root of your installation
  30. root /usr/share/webapps/nextcloud/;

  31. location = /robots.txt {
  32. allow all;
  33. log_not_found off;
  34. access_log off;
  35. }

  36. # The following 2 rules are only needed for the user_webfinger app.
  37. # Uncomment it if you're planning to use this app.
  38. #rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
  39. #rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json
  40. # last;

  41. location = /.well-known/carddav {
  42. return 301 $scheme://$host/remote.php/dav;
  43. }
  44. location = /.well-known/caldav {
  45. return 301 $scheme://$host/remote.php/dav;
  46. }

  47. # set max upload size
  48. client_max_body_size 512M;
  49. fastcgi_buffers 64 4K;

  50. # Disable gzip to avoid the removal of the ETag header
  51. gzip off;

  52. # Uncomment if your server is build with the ngx_pagespeed module
  53. # This module is currently not supported.
  54. #pagespeed off;

  55. error_page 403 /core/templates/403.php;
  56. error_page 404 /core/templates/404.php;

  57. location / {
  58. rewrite ^ /index.php$uri;
  59. }

  60. location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
  61. deny all;
  62. }
  63. location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
  64. deny all;
  65. }

  66. location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
  67. fastcgi_split_path_info ^(.+\.php)(/.*)$;
  68. include fastcgi_params;
  69. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  70. fastcgi_param PATH_INFO $fastcgi_path_info;
  71. fastcgi_param HTTPS on;
  72. #Avoid sending the security headers twice
  73. fastcgi_param modHeadersAvailable true;
  74. fastcgi_param front_controller_active true;
  75. fastcgi_pass php-handler;
  76. fastcgi_intercept_errors on;
  77. fastcgi_request_buffering off;
  78. }

  79. location ~ ^/(?:updater|ocs-provider)(?:$|/) {
  80. try_files $uri/ =404;
  81. index index.php;
  82. }

  83. # Adding the cache control header for js and css files
  84. # Make sure it is BELOW the PHP block
  85. location ~* \.(?:css|js|woff|svg|gif)$ {
  86. try_files $uri /index.php$uri$is_args$args;
  87. add_header Cache-Control "public, max-age=7200";
  88. # Add headers to serve security related headers (It is intended to
  89. # have those duplicated to the ones above)
  90. # Before enabling Strict-Transport-Security headers please read into
  91. # this topic first.
  92. # add_header Strict-Transport-Security "max-age=15768000;
  93. # includeSubDomains; preload;";
  94. add_header X-Content-Type-Options nosniff;
  95. add_header X-Frame-Options "SAMEORIGIN";
  96. add_header X-XSS-Protection "1; mode=block";
  97. add_header X-Robots-Tag none;
  98. add_header X-Download-Options noopen;
  99. add_header X-Permitted-Cross-Domain-Policies none;
  100. # Optional: Don't log access to assets
  101. access_log off;
  102. }

  103. location ~* \.(?:png|html|ttf|ico|jpg|jpeg)$ {
  104. try_files $uri /index.php$uri$is_args$args;
  105. # Optional: Don't log access to other assets
  106. access_log off;
  107. }
  108. }

Set ownership on /usr/share/webapps/nextcloud

$ sudo chown http:http -R /usr/share/webapps/nextcloud

Generate /etc/webapps/nextcloud/config/php.config

$ cd /usr/share/webapps/nextcloud

$ sudo -u http php occ maintenance:install --database

"mysql" --database-host “localhost:/var/run/mysqld/mysqld.sock” --database-name “nextcloud” --database-user “nextcloud” --database-pass

"xxxx" --admin-user “llwang” --admin-pass “xxxx”

Import server.crt in ‘opera or chrome’

  1. 选项-->高级设置-->管理证书-->导入

$ opera “https://xxx.com:8080


nicephil@gmail.com